From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B8A1C27C4F for ; Fri, 21 Jun 2024 15:45:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25B256B00EC; Fri, 21 Jun 2024 11:45:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00CF96B00ED; Fri, 21 Jun 2024 11:45:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D55206B00F0; Fri, 21 Jun 2024 11:45:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B0CD06B00EC for ; Fri, 21 Jun 2024 11:45:42 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2587D1A1045 for ; Fri, 21 Jun 2024 15:45:42 +0000 (UTC) X-FDA: 82255320924.16.2D0EF08 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id E75364000B for ; Fri, 21 Jun 2024 15:45:38 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="hb2Ar6x/"; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718984725; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DvV7QxN2N8EkXiFQ37jwVC1N3GHUF6ZxiwTS9PAYN+c=; b=dE94X4FJEA3hzg6QkrCfZA2xek33tL25ldSY0L/kZHtPg6TsU2Y+SFPVlJ87B5sR575qAs kJmZvGXjS4hp+1HvfyY6a0uPoLB/p1rqeIhlVpN1gUvXzJ+pka4G9UJivNEe7VRp2ISk6e uR+itM/DaUMZap5paM9rqO3dyM59Vsc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="hb2Ar6x/"; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718984725; a=rsa-sha256; cv=none; b=A0GiP3EvgbVKlcvKrwJX3FSYPW0igUJ821jZtm/ztX5TzWT+Jf2h9q5pgQEHLI11xWjXDq cvV7gGtb6vyRg1AytLvwZpKpvYOTAZMqZI5AcnUjVO7ZF9VmtH4ZN6lNnHvOObCVlCRUyr ltJs4tsVQOTHQATSVMS6cQlIF5IaGdI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718984738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DvV7QxN2N8EkXiFQ37jwVC1N3GHUF6ZxiwTS9PAYN+c=; b=hb2Ar6x/9IdhK944nJrDL1Y7O+RGaZi07GpSjDCvR4ipvIf2NoYw3bpL2r/uap44b0cJXj IRc9XNFIiwG+hEC0GF8AuuQnCBn9HcZRYLI6afEscn7m3RBlNUtnHL2GkKGRm8UKHOtph9 fjdXNnAVtU9ev8vqkhD90RP8P5jUPxU= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-567-W4HbTSgkO3iVVYwxi4q9xA-1; Fri, 21 Jun 2024 11:45:36 -0400 X-MC-Unique: W4HbTSgkO3iVVYwxi4q9xA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-79560b25fc4so16758985a.3 for ; Fri, 21 Jun 2024 08:45:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718984736; x=1719589536; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=DvV7QxN2N8EkXiFQ37jwVC1N3GHUF6ZxiwTS9PAYN+c=; b=Y3Kl2HXRbZFW+uh7e6EC5UX1WfBJ8VYQSFEYi04apP2vB/th8KzIu1J7vn4WjNHGS9 mNkM+XMb5GeVZTbvAhOVY26VOja9kFuHwiotBAmc+gm3LlZXwgzPwAdmnYfeIEiAQJhO wPb3M0wO4Sc4HIzKiPxV5Ht1lQj8NjI1ItBhRnloJ/HoSmygb0kM3Y/WpnmueYXG3R+7 ajk02jgCkr29i8D8jJBqa8f5IS0gZY/txd3dD3hr/rEcZn3+uh3+Oag6reQzkJsRTjMZ pWbTE045CRBBriamUAG/v1tRFKhKxJuOKNMUcR1NUxzZcPHQzdsT252z7JqHxJl6ES4d Ed5w== X-Forwarded-Encrypted: i=1; AJvYcCX465Y+81MRj4k9vRY+LhuJrY7n0LIbaKSadJ0eIRrCEExNi+6SVPkdi1wxMf6vwWDUNv1sTcrsZz85fgceJYXMuzI= X-Gm-Message-State: AOJu0YxSOtH2DWPZ+0RvFa4gFrHi3SkNOqlSvKfN8/SSYjMzjB3ldpqT Dc8TPRSMVUTIzkc3TvomAfNMfwJoLPi1pn/j27czLTFUfYEVacEUPXQ9B1VkcNSkRVkupWyBbn7 0T3HbpWe55yROLMvHhvn6tRfCHG3s5qocH38bZ8c9R3xuK3Ch X-Received: by 2002:ad4:5be2:0:b0:6b2:bfe2:70c3 with SMTP id 6a1803df08f44-6b501ede972mr90358066d6.4.1718984735679; Fri, 21 Jun 2024 08:45:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGB4nZlIY0H/jVph74+0l9c524qednI2eEp5OI3eX2TFxMHuOsOPAnloJuGVmQCrkbVd6KN2g== X-Received: by 2002:ad4:5be2:0:b0:6b2:bfe2:70c3 with SMTP id 6a1803df08f44-6b501ede972mr90357756d6.4.1718984735058; Fri, 21 Jun 2024 08:45:35 -0700 (PDT) Received: from x1n (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b51ef4b1f7sm9609536d6.108.2024.06.21.08.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 08:45:34 -0700 (PDT) Date: Fri, 21 Jun 2024 11:45:31 -0400 From: Peter Xu To: Dave Hansen Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, Borislav Petkov , Dave Jiang , "Kirill A . Shutemov" , Ingo Molnar , Oscar Salvador , Matthew Wilcox , Vlastimil Babka , Dan Williams , Andrew Morton , Hugh Dickins , Michael Ellerman , Dave Hansen , Thomas Gleixner , linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Rik van Riel , Mel Gorman , "Aneesh Kumar K . V" , Nicholas Piggin , Huang Ying , "Edgecombe, Rick P" Subject: Re: [PATCH 6/7] mm/x86: Add missing pud helpers Message-ID: References: <20240621142504.1940209-1-peterx@redhat.com> <20240621142504.1940209-7-peterx@redhat.com> <4fb4b087-cae2-4516-a34e-cb4c72be13eb@intel.com> MIME-Version: 1.0 In-Reply-To: <4fb4b087-cae2-4516-a34e-cb4c72be13eb@intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E75364000B X-Stat-Signature: mgst859fntsy6d5okxs8b4yd5gzjqpc9 X-Rspam-User: X-HE-Tag: 1718984738-822786 X-HE-Meta: U2FsdGVkX18bo3eo5fZSRUsWkuPkBqzwUaJ0szYVO/V+xhyVyTAZPBZ7U8zAUzuLMVayePupUGhXbHwvmcxqxBzfANtUXkUEjHb5F011eHaJrsVqAkOUr06JhE46hAFS/GpcScwGVnbbakL3r3NmkZAucF3J4LmxQ8Ez5u9rXU0URJ1ElnyCHvnsqNPI486icJYwR859wVMTrQiSzupDhRkC8KRLfc+VD+lroduhjzxVSlJygnCjShIMJGeB1lt3IfEZ+AAL1W8EuSVUdLAPPS85td7tdkS7gxOZt1IL/5Xy+sKJFtjhkwMQYzWJ5PATxLJqaM/PdksGvuQo080jMwfeOGaqZdgRZ0SQEoGEcKcthrDQZweARa5j+xw+aB/L6Jh82qpPw4N0usVCLyUvoc7F2TdGzAlgoekA/+Gy+/VwPmxgohHEiZRpbFwtJuUBDLIn2DPBteV94q+ZIb0SbHeUKAXPEJwFS/x6/3XfFc98+geIA5xVg7+wa+GZt4tpwAW4kOlX/4c/FNkdnjEtdd1ULePjC8eeGJuz7ooG+ffbKQbUd5xoUb90MYFS/buyK839Uxi745sv9TLami3RT81NTyvLkn5S4ZoDyXCuRuXpLmCFYO/ddP9B0zYOtLJIynQ9IGiefol+FPwWf4OdwNgEXFl8QqPE3tg14MMKQFg5KDpL2WXi0g7yIGerWTr+uFYFg2k34CLSlIZnqmzdxio7RgdgN7ti3y1cMcAxvjltcrVl0QPc97cWhCTxWm8kGgM3TsQ5o9mS6fB8FzHFxtVub0lu4eIgBY14e5K+oNV+w6U1N1sLyMpHQuk/AB1/g9MERM8VETmBsKx+4xWEegSpZKOWPLqhraZhJ556p2cKx4F0kBNLFe9JI7JXIJKETwjoV7gx3c3kFs7SdqTO5Rq/mgP7tvL2OmeJ0ycKrs0Bkw2nR5MwNO7yUT/nxLSj72KW54hl6GerP8LCljU Z16EgxdU 2MixzsvYu3mMyTzU7FAcPqIVp9aoBOtRPB7XfasP3dzZTzr8c8pPKbuKelhU3GBysHBsFQaFhrdcL28llLVg0ulIuBuIKvJ5MmIvAI7S35x1PgANEvziRjqIQKELReXxh3XP1CmCkdCWySBcQA/PkOxMct4iX7G2BLD3pNeq4bajDUsIcv/OTr3lZMTwlsI4xxxzCfxdkGqsddqtdiPhgAfl1Y7WKzY/sz5m/lSkAVY5UBZvd5F2vTD7uB9uG2Io9c5a3BZkfMJckbONWi27SSAX9K5rRqiuNDV8SwlUwrKJ6GM6rQr0hSOKRr71YmoUEp3OxzlQHeaZiDS/yosKUmUXJCuwDaBE4nT0Q2GyKSqDWTGBZL6Z8vosnM5sgCHnAejoB3DX9227hBlE5F3hrHp55M4Q7VD6mZM/G66HcD9+HudpyosudFtIjn2KHZQ6/LJ7Q X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Jun 21, 2024 at 07:51:26AM -0700, Dave Hansen wrote: > On 6/21/24 07:25, Peter Xu wrote: > > These new helpers will be needed for pud entry updates soon. Namely: > > > > - pudp_invalidate() > > - pud_modify() > > I think it's also definitely worth noting where you got this code from. > Presumably you copied, pasted and modified the PMD code. That's fine, > but it should be called out. Yes that's from PMD ones. Sure, I will add that. > > ... > > +static inline pud_t pud_modify(pud_t pud, pgprot_t newprot) > > +{ > > + pudval_t val = pud_val(pud), oldval = val; > > + > > + /* > > + * NOTE: no need to consider shadow stack complexities because it > > + * doesn't support 1G mappings. > > + */ > > + val &= _HPAGE_CHG_MASK; > > + val |= check_pgprot(newprot) & ~_HPAGE_CHG_MASK; > > + val = flip_protnone_guard(oldval, val, PHYSICAL_PUD_PAGE_MASK); > > + > > + return __pud(val); > > +} > > First of all, the comment to explain what you didn't do here is as many > lines as the code to _actually_ implement it. > > Second, I believe this might have missed the purpose of the "shadow > stack complexities". The pmd/pte code is there not to support modifying > shadow stack mappings, it's there to avoid inadvertent shadow stack > mapping creation. > > That "NOTE:" is ambiguous as to whether the shadow stacks aren't > supported on 1G mappings in Linux or the hardware (I just checked the > hardware docs and don't see anything making 1G mappings special, btw). Right this could be ambiguous indeed; I was trying to refer to the fact where shadow stack is only supported on anon, and anon doesn't support 1G. But looks like I'm more than wrong than that.. > > But, still, what if you take a Dirty=1,Write=1 pud and pud_modify() it > to make it Dirty=1,Write=0? What prevents that from being > misinterpreted by the hardware as being a valid 1G shadow stack mapping? Thanks for pointing that out. I think I was thinking it will only take effect on VM_SHADOW_STACK first, so it's not? I was indeed trying to find more information on shadow stack at that time but I can't find as much on the pgtable implications, on e.g. whether "D=1 + W=0" globally will be recognized as shadow stack. At least on SDM March 2024 version Vol3 Chap4 pgtable entries still don't explain these details, or maybe I missed it. Please let me know if there's suggestion on what I can read before I post a v2. So if it's globally taking effect, indeed we'll need to handle them in PUDs too. Asides, not sure whether it's off-topic to ask here, but... why shadow stack doesn't reuse an old soft-bit to explicitly mark "this is shadow stack ptes" when designing the spec? Now it consumed bit 58 anyway for caching dirty. IIUC we can avoid all these "move back and forth" issue on dirty bit if so. > > > /* > > * mprotect needs to preserve PAT and encryption bits when updating > > * vm_page_prot > > @@ -1377,10 +1398,25 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma, > > } > > #endif > > > > +static inline pud_t pudp_establish(struct vm_area_struct *vma, > > + unsigned long address, pud_t *pudp, pud_t pud) > > +{ > > + if (IS_ENABLED(CONFIG_SMP)) { > > + return xchg(pudp, pud); > > + } else { > > + pud_t old = *pudp; > > + WRITE_ONCE(*pudp, pud); > > + return old; > > + } > > +} > > Why is there no: > > page_table_check_pud_set(vma->vm_mm, pudp, pud); > > ? Sure, it doesn't _do_ anything today. But the PMD code has it today. > So leaving it out creates a divergence that honestly can only serve to > bite us in the future and will create a head-scratching delta for anyone > that is comparing PUD and PMD implementations in the future. Good question, I really don't remember why I didn't have that, since I should have referenced the pmd helper. I'll add them and see whether I'll hit something otherwise. Thanks for the review. -- Peter Xu