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 0A670CD4853 for ; Wed, 4 Sep 2024 16:54:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.790621.1200462 (Exim 4.92) (envelope-from ) id 1sltHD-0008DY-VG; Wed, 04 Sep 2024 16:54:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 790621.1200462; Wed, 04 Sep 2024 16:54:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sltHD-0008DR-Sk; Wed, 04 Sep 2024 16:54:39 +0000 Received: by outflank-mailman (input) for mailman id 790621; Wed, 04 Sep 2024 16:54:38 +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 1sltHC-0008DL-6m for xen-devel@lists.xenproject.org; Wed, 04 Sep 2024 16:54:38 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5dc0e388-6ade-11ef-99a1-01e77a169b0f; Wed, 04 Sep 2024 18:54:36 +0200 (CEST) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a869f6ce2b9so745526466b.2 for ; Wed, 04 Sep 2024 09:54:36 -0700 (PDT) Received: from [10.125.226.166] ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a6236d26esm13867966b.140.2024.09.04.09.54.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Sep 2024 09:54:33 -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: 5dc0e388-6ade-11ef-99a1-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1725468875; x=1726073675; 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=Qyd7w+L/xrw+NC5fGqs/6jsapBhr3Ds73qSX/+2joyw=; b=ifDC7O6CUBX9tzXcr0xeYnJ9TaTEEv3SywW7vw3fI3PTPdhlwixppGEuyjBuk8o7t2 6I+M8IXL3rxFfHaRaOr2Y6CYSrzsAo/eHKaTlvTzD4dcPCe2b2gMp130CrUIt1Ol3s3O AFg0PetuaO9cvy1q3ds7C2Wk2RL2cJkFEPKXo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725468875; x=1726073675; 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=Qyd7w+L/xrw+NC5fGqs/6jsapBhr3Ds73qSX/+2joyw=; b=iXOWF2OTKsQaLu2zHFCX9x46UsBZKgpVtZGLJpWXf2Wunl0QMvGYgQAaU+2cniawfR MxDuASl0DztkzsNpHRWjXOkljdbD8HLm0LzvVHOLDZPZDCD1xKfdV80Z31io28NhAkdz J9C/0GyJ+zOKvFu6ri946lkU7T8+FxPLKyYlxpgRSvRY9pT1wutPLbzj6b8gU+677fBG 7k99AAbHr76t0gd/LVZB2UYZEJ4QvDn4MS3akHMdfsmITJ8/UI+nEAXBF8PzoTRILd1G Sl9DbPD6iXV/v4IgXm+sCgCg1IDNonpJdcilEUl1iUuljp+kxoMrsO6a4yeTTxwcxHhR UBZw== X-Forwarded-Encrypted: i=1; AJvYcCW1mnNtGsGBsm4sXfmxBmltWZeUBpREGg2o6OZtZxwMHEr0iEqOOTgKsySd8Vheicer/UK2txoKP+s=@lists.xenproject.org X-Gm-Message-State: AOJu0YxSy3gZ5cgfvxRF9wLXQGEUwXaxoSv0vzNpCodmMUpx4qoEZqT6 gjcB6fuUAI6XU+UYD7BI7GyREcoskbh4lMnK3erp/0fjj8CpX4ugfVscx54KneI= X-Google-Smtp-Source: AGHT+IGe89jylxx92teOrgVagqr9N42z5k6+clxmPzmjPlK+T0pDiINA5KDGHAjwyH3J1zLWiZWrEA== X-Received: by 2002:a17:907:3e20:b0:a7a:aa35:409e with SMTP id a640c23a62f3a-a8a32e744ebmr438118466b.25.1725468874917; Wed, 04 Sep 2024 09:54:34 -0700 (PDT) Message-ID: Date: Wed, 4 Sep 2024 17:54:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 4/7] x86: introduce x86_seg_sys To: Jan Beulich , "xen-devel@lists.xenproject.org" Cc: Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: <0b9a0ae8-a39c-49d8-b4e7-f2a463128058@suse.com> <2848ec72-6e26-4331-a218-0e3e8f16572f@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+1I4jsRQQh2m6OTADHIqg2E ofTYAEh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rAtIa1k01sPipPPw6dfxx2e5asy21YOytzxuWFfJTGnVxZZSCyLUO83sh6OZhJkk b9rxL9wPmpN/t2IPaEKoAc0FTQZS36wAMOXkBh24PQ9gaLJvfPKpNzGD8XWR5HHF0NLIJhgg 4ZlEXQ2fVp3XrtocHqhu4UZR4koCijgB8sB7Tb0GCpwK+C4UePdFLfhKyRdSXuvY3AHJd4CP 4JzW0Bzq/WXY3XMOzUTYApGQpnUpdOmuQSfpV9MQO+/jo7r6yPbxT7CwRS5dcQPzUiuHLK9i nvjREdh84qycnx0/6dDroYhp0DFv4udxuAvt1h4wGwTPRQZerSm4xaYegEFusyhbZrI0U9tJ B8WrhBLXDiYlyJT6zOV2yZFuW47VrLsjYnHwn27hmxTC/7tvG3euCklmkn9Sl9IAKFu29RSo d5bD8kMSCYsTqtTfT6W4A3qHGvIDta3ptLYpIAOD2sY3GYq2nf3Bbzx81wZK14JdDDHUX2Rs 6+ahAA== In-Reply-To: <2848ec72-6e26-4331-a218-0e3e8f16572f@suse.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 04/09/2024 1:29 pm, Jan Beulich wrote: > To represent the USER-MSR bitmap access, a new segment type needs > introducing, behaving like x86_seg_none in terms of address treatment, > but behaving like a system segment for page walk purposes (implicit > supervisor-mode access). > > Signed-off-by: Jan Beulich > --- > This feels a little fragile: Of course I did look through uses of the > enumerators, and I didn't find further places which would need > adjustment, but I'm not really sure I didn't miss any place. It does feel a bit fragile, but it may help to consider the other related cases. Here, we need a linear access with implicit-supervisor paging properties.  From what I can tell, it needs to be exactly like other implicit supervisor accesses. For CET, we get two new cases. The legacy bitmap has a pointer out of MSR_[U,S]_CET, but otherwise obeys CPL rules, so wants to be x86_seg_none. However, WRUSS is both a CPL0 instruction, and generates implicit-user accesses.  It's the first instruction of it's like, that I'm aware of.  If we're going down this x86_seg_sys route, we'd need x86_seg_user too. Really, this is a consequence of the memory APIs we've got.  It's the intermediate layers which generate PFEC_* for the pagewalk, and we're (ab)using segment at the top level to encode "skip segmentation but I still want certain properties". But, there's actually a 3rd case we get from CET, and it breaks everything. Shstk accesses are a new type, architecturally expressed as a new input (and output) to the pagewalk, but are also regular user-segment relative. We either do the same trick of expressing fetch() in terms of read(PFEC_insn) and implement new shstk_{read,write}() accessors which wrap {read,write}(PFEC_shstk), or we need to plumb the PFEC parameters higher in the call tree. It's worth noting that alignment restrictions make things even more complicated.  Generally, shstk accesses should be 8 or 4 byte aligned (based on osize), and the pseudocode for WR{U}SS calls this out; after all they're converting from arbitrary memory operands. However, there's a fun corner case where a 64bit code segment can use INCSSPD to misalign SSP, then CALL to generate a misaligned store.  This combines with an erratum in Zen3 and possibly Zen4 where there's a missing #GP check on LRET and you can forge a return address formed of two misaligned addresses. So misaligned stores are definitely possible (I checked this on both vendors at the time), so it wouldn't be appropriate to have in a general shstk_*() helper.  In turn, this means that the implementation of WR{U}SS would need a way to linearise it's operand manually to insert the additional check before then making a regular memory access. And I can't see a way of doing this without exposing PFEC inputs at the top level. Thoughts? ~Andrew