Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E71A8E6FE46 for ; Fri, 6 Sep 2024 19:20:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.792013.1202065 (Exim 4.92) (envelope-from ) id 1smeVD-0000Nv-Lh; Fri, 06 Sep 2024 19:20:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 792013.1202065; Fri, 06 Sep 2024 19:20:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1smeVD-0000No-Hw; Fri, 06 Sep 2024 19:20:15 +0000 Received: by outflank-mailman (input) for mailman id 792013; Fri, 06 Sep 2024 19:20:15 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1smeVC-0000Nh-V4 for xen-devel@lists.xenproject.org; Fri, 06 Sep 2024 19:20:14 +0000 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [2a00:1450:4864:20::52e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 09f40a9e-6c85-11ef-99a1-01e77a169b0f; Fri, 06 Sep 2024 21:20:12 +0200 (CEST) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5c2561e8041so2667296a12.2 for ; Fri, 06 Sep 2024 12:20:12 -0700 (PDT) Received: from [10.125.226.166] ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a6236d527sm310198666b.135.2024.09.06.12.20.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2024 12:20:11 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 09f40a9e-6c85-11ef-99a1-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1725650412; x=1726255212; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=ujcBfhl2qeHig0fN5Ls/vjy9AU7OiAZ/U3DXlqnsx3k=; b=EgRil9sfEhk4E07sAgpPOxskz47ONCbkx4Ysu9MxF1ybUsECnstYMVMGy8nk8Vh3qM K8X+8NYdK2zbjJnymbY7fHa+cIR5RC8BaEUsd/XUM4wB2ckea82mLyUDSlPzSzG86qfi n5eWTgYHJCNmGCo189boNh7MtBrqkv4PjY5pE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725650412; x=1726255212; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ujcBfhl2qeHig0fN5Ls/vjy9AU7OiAZ/U3DXlqnsx3k=; b=WM/KztR9PZ9PKHXTYvrUhb3b7wiTBpsXFDxkbIdOzJfT0PHskxBC+Yni5HibIlxGJc dGCjLkLe11jqk6HHBCwbruFzD0ZU+WHYNkF71vV5AA+aBtdAYoDOUjYyCXMsqN5wEsOS wDTncQoLdF3NFz/JV6o/XClWyE0w5HY58h4hRiLzlLN6wvDeZGc0cqDYffZC4UrK6ARE fIBnwdKFTkMW1ul6DT4D+Y7lomdyEnHVZAgqWjMfpXpfdjMIqjqXKow8zpCS4DXDTvA+ YX1QZnbx0LP4a2lxau/xKjJ+1qmpqkTmKmMYa14SH73xYdxwsUgKzHbEhZHN4BlhA4Tg yHpA== X-Forwarded-Encrypted: i=1; AJvYcCVYOwfbjqGXZP//DdCCTRqyOhVpUCgPaDRKCwruz7ZmOo5BG7cmsN2n8PXleIueC500/awjXRg3qE4=@lists.xenproject.org X-Gm-Message-State: AOJu0Yw3zATWAgbOeLWWg4+h5UOgmzx/ma7KiDZagMZmpMloqv69GIcP dm2KRHS0INkUKbDPmZmBlJJkUpyosDJhiRY7B03T/k/0Vx/nxbCJ6qLfTJKxRP5Suoa6QHIRmYD y X-Google-Smtp-Source: AGHT+IE6V+IPR+q4iv2lEGIvMhOPJb0/l8O5pPYnirORg2pnIkRgyyg5cKEgPPRT1bVOfGAURgi0Ww== X-Received: by 2002:a17:906:eec7:b0:a88:b90b:bd5e with SMTP id a640c23a62f3a-a8a885be339mr258697866b.3.1725650411535; Fri, 06 Sep 2024 12:20:11 -0700 (PDT) Message-ID: <53ecfaa0-3be1-4da0-ad8d-8245512e4172@citrix.com> Date: Fri, 6 Sep 2024 20:20:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/5] x86/HVM: allocate emulation cache entries dynamically To: Jan Beulich , "xen-devel@lists.xenproject.org" Cc: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: <31906cba-8646-4cf9-ab31-1d23654df8d1@suse.com> Content-Language: en-GB From: Andrew Cooper Autocrypt: addr=andrew.cooper3@citrix.com; keydata= xsFNBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTIb+OlMSJUWV4opS7WVNnxHbFTPYZVQ3erv7NKc2iVizCRZ2Kxn srM1oPXWRic8BIAdYOKOloF2300SL/bIpeD+x7h3w9B/qez7nOin5NzkxgFoaUeIal12pXSR Q354FKFoy6Vh96gc4VRqte3jw8mPuJQpfws+Pb+swvSf/i1q1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ZD4Xu9kU2IXYmuW+e5KCA vTArRUdCrAtIa1k01sPipPPw6dfxx2e5asy21YOytzxuWFfJTGnVxZZSCyLUO83sh6OZhJkk b9rxL9wPmpN/t2IPaEKoAc0FTQZS36wAMOXkBh24PQ9gaLJvfPKpNzGD8XWR5HHF0NLIJhgg 4ZlEXQ2fVp3XrtocHqhu4UZR4koCijgB8sB7Tb0GCpwK+C4UePdFLfhKyRdSXuvY3AHJd4CP 4JzW0Bzq/WXY3XMOzUTYApGQpnUpdOmuQSfpV9MQO+/jo7r6yPbxT7CwRS5dcQPzUiuHLK9i nvjREdh84qycnx0/6dDroYhp0DFv4udxuAvt1h4wGwTPRQZerSm4xaYegEFusyhbZrI0U9tJ B8WrhBLXDiYlyJT6zOV2yZFuW47VrLsjYnHwn27hmxTC/7tvG3euCklmkn9Sl9IAKFu29RSo d5bD8kMSCYsTqtTfT6W4A3qHGvIDta3ptLYpIAOD2sY3GYq2nf3Bbzx81wZK14JdDDHUX2Rs 6+ahAA== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 04/09/2024 2:29 pm, Jan Beulich wrote: > Both caches may need higher capacity, and the upper bound will need to > be determined dynamically based on CPUID policy (for AMX at least). Is this to cope with TILE{LOAD,STORE}, or something else? It's not exactly clear, even when looking at prior AMX series. > While touching the check in hvmemul_phys_mmio_access() anyway, also > tighten it: To avoid overrunning the internal buffer we need to take the > offset into the buffer into account. Does this really want to be mixed with a prep patch ? > > Signed-off-by: Jan Beulich > --- > This is a patch taken from the AMX series, which was part of the v3 > submission. All I did is strip out the actual AMX bits (from > hvmemul_cache_init()), plus of course change the description. As a > result some local variables there may look unnecessary, but this way > it's going to be less churn when the AMX bits are added. The next patch > pretty strongly depends on the changed approach (contextually, not so > much functionally), and I'd really like to avoid rebasing that one ahead > of this one, and then this one on top of that. Fine by me. > --- a/xen/arch/x86/hvm/emulate.c > +++ b/xen/arch/x86/hvm/emulate.c > @@ -26,6 +26,18 @@ > #include > #include > > +/* > + * We may read or write up to m512 or up to a tile row as a number of > + * device-model transactions. > + */ > +struct hvm_mmio_cache { > + unsigned long gla; > + unsigned int size; > + unsigned int space:31; > + unsigned int dir:1; > + uint8_t buffer[] __aligned(sizeof(long)); I know this is a minor tangent, but you are turning a regular struct into a flexible one. Could we introduce __counted_by() and start using it here? At the toolchain level, it lets the compiler understand the real size of the object, so e.g. the sanitisers can spot out-of-bounds accesses through the flexible member. But, even in the short term, having     /* TODO */     # define __counted_by(member) in compiler.h still leaves us with better code, because     struct hvm_mmio_cache {         unsigned long gla;         unsigned int size;         unsigned int space:31;         unsigned int dir:1;         uint8_t buffer[] __aligned(sizeof(long)) __counted_by(size);     }; is explicitly clear in a case where the "space" field creates some ambiguity. > @@ -2978,16 +2991,21 @@ void hvm_dump_emulation_state(const char > int hvmemul_cache_init(struct vcpu *v) > { > /* > - * No insn can access more than 16 independent linear addresses (AVX512F > - * scatters/gathers being the worst). Each such linear range can span a > - * page boundary, i.e. may require two page walks. Account for each insn > - * byte individually, for simplicity. > + * AVX512F scatter/gather insns can access up to 16 independent linear > + * addresses, up to 8 bytes size. Each such linear range can span a page > + * boundary, i.e. may require two page walks. > + */ > + unsigned int nents = 16 * 2 * (CONFIG_PAGING_LEVELS + 1); > + unsigned int i, max_bytes = 64; > + struct hvmemul_cache *cache; > + > + /* > + * Account for each insn byte individually, both for simplicity and to > + * leave some slack space. > */ Hang on.  Do we seriously use a separate cache entry for each instruction byte ? ~Andrew