Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1058030pxm; Wed, 23 Feb 2022 17:03:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSbaUcU8zPeW6v3SklaY++v92aKZqRSz7ZZgNH+yI+ueJaEA9BVRt3XRlHDiXmMtgdWh6S X-Received: by 2002:a17:902:ef4f:b0:14f:a7bc:8357 with SMTP id e15-20020a170902ef4f00b0014fa7bc8357mr137708plx.19.1645664585792; Wed, 23 Feb 2022 17:03:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645664585; cv=none; d=google.com; s=arc-20160816; b=nDdW3rqPxW69oVlywjMmhiIr8vstx1tQN/4j3rWBhlBooZf8ZbsBXOTYDDEENYm1Z1 4VHYIa9uKinQQ4M/jmc5BCo9EaIjuWRQy2AxlQ7aZ0pAWShP94TX1eYypjwE9PoHZurL TpJ1YBbEqdUL7lzB3hwCRhIzuuROJPzCEp8gS+0HiLmJ3/S1f/Lp03o/n2lb7AKinY0A f1re2Lz72tUgMbGCp9kmvDlTFS465QBbVy2Or3CrTIgszcdjYHY/zVFfnxUriXRkMrfW Npc7W14sGk7PDfTIJDu8XPS+tO6nrvtp/2cvf59KY+xfk+25enXe5EpNSXs+2qtMjU8U NMJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=ObwiCZnkzVE8MG/ZKfaaMbJx1EDS+iQex1h+i9r1lWc=; b=qWIU5a+deLHR9lx4dbcheRX0zIWnFRT7m0bnRWtS4kOGN/VOnPQgWEJ2+OkLn6EtvC KrUFhuuke1ZAQR7nb/G3DMVKbST4PGtRnETcq08xJea8KUCS72/R3obzik7b3oDEC8L2 myjwayzBexVS26NL2DeDhjSzJIdrKq375E4hK89twX/+4RzPnCaQPxqY9+59IC/3kGF8 X3Ipu3CpvFhgpabQvNZ0yUecoLinhC5jH4H0y7U4Hkq6a4lxlqsfyDPFSxD5e47vYddn TK0nESBdTvr4qTBE6W0RQ859a5UbkniK0wCDJ9x/fbsyudmv0R/6RBHC//vIDEzKpLEb py7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gZ9xDnCT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x17si1205800plg.316.2022.02.23.17.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 17:03:05 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gZ9xDnCT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E913A13EFAE; Wed, 23 Feb 2022 16:53:27 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238253AbiBWF0F (ORCPT + 99 others); Wed, 23 Feb 2022 00:26:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238226AbiBWFZf (ORCPT ); Wed, 23 Feb 2022 00:25:35 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C2ED6AA56 for ; Tue, 22 Feb 2022 21:24:31 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id k7-20020a255607000000b00621afc793b8so26767243ybb.1 for ; Tue, 22 Feb 2022 21:24:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ObwiCZnkzVE8MG/ZKfaaMbJx1EDS+iQex1h+i9r1lWc=; b=gZ9xDnCTT9J2il7FQZjHDQXU7P24qq79E3XEa26PGLeqDS7nHRklN55Z0YrbQllfvk a54Tnc7QS05X1TZviBvKI6s2J4e0JaxU2Mc4n2JddMKt6uhs1bA5ThP/H5jQeUIa+Q5L YzXtSBRLRL23nYFayWpilSuGrgyaEtzeVJtrSMs+fJOYlGhJTGeNFUiGfho3OKAJCQvL xqhDtH8EyJDw3FY1cTPmzwnJaSBjdeIgm+usm4Xbnvmu4zwwAyO/ya/YpXR5JHhjT9H0 Wpbgj5s5UiyqBd60tJZ8fxwBXyX5DCw1p9aGG11pd0ckG2SC7DJ9q4R1uxUVnHb2V4YR +hNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ObwiCZnkzVE8MG/ZKfaaMbJx1EDS+iQex1h+i9r1lWc=; b=STXMqOZ2fnkcMaAIwO6uZ7xOxuFUZ7HT3oUA/+NKyED/khOBjdxeM8eZMW+mviHxsv aOZ3643VLS8C9qkblxbsApK6ARkw+H3xmk8YiLhuGIAN7F+2WCq97RMrSrWdWMQbsIcW +PG9n4yLPIa1Cu3RKsBUxbEyGxUWdy7Xn2SZq+KGxiOfojgq4CvdZPwC/HVuazOgEab7 vsrLAwNya4ulqkyQJDrfL6L5lSpzfL0npUqfdv8smNyZ2lDHkaY3xM5IIshnsMOAqCrU Gcj8Ipkpg3n+DNZzgcUUj3pr810QSYG0ocxG3OyTjtW1gDs0qyzFHkI6OIpwKPRoratS QNXA== X-Gm-Message-State: AOAM530Zo72AAbdVrLPs1WWY/w7+cYvhfCFoDlxJHancSLJrhwdp/zm9 B6yrVnce/mbQ2XSpQIWcFZiNZ/jJFeKB4WBLcvNbXqVzfQoH1+EYbF/qiaZ1r94f+Udn6LTdvZ5 baEAEC78kpRhCf5dSI5odMyFwQwGSv7+PGu4NNsvn/3ecxMSqBMJz/mDhKBwjWnEDHbx4I5lu X-Received: from js-desktop.svl.corp.google.com ([2620:15c:2cd:202:ccbe:5d15:e2e6:322]) (user=junaids job=sendgmr) by 2002:a0d:db0d:0:b0:2d0:e912:3e47 with SMTP id d13-20020a0ddb0d000000b002d0e9123e47mr27008531ywe.23.1645593857064; Tue, 22 Feb 2022 21:24:17 -0800 (PST) Date: Tue, 22 Feb 2022 21:21:50 -0800 In-Reply-To: <20220223052223.1202152-1-junaids@google.com> Message-Id: <20220223052223.1202152-15-junaids@google.com> Mime-Version: 1.0 References: <20220223052223.1202152-1-junaids@google.com> X-Mailer: git-send-email 2.35.1.473.g83b2b277ed-goog Subject: [RFC PATCH 14/47] mm: asi: Disable ASI API when ASI is not enabled for a process From: Junaid Shahid To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, pbonzini@redhat.com, jmattson@google.com, pjt@google.com, oweisse@google.com, alexandre.chartre@oracle.com, rppt@linux.ibm.com, dave.hansen@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, luto@kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If ASI is not enabled for a process, then asi_init() will return a NULL ASI pointer as output, though it will return a 0 error code. All other ASI API functions will return without an error when they get a NULL ASI pointer. Signed-off-by: Junaid Shahid --- arch/x86/include/asm/asi.h | 2 +- arch/x86/mm/asi.c | 18 ++++++++++-------- include/asm-generic/asi.h | 7 ++++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/asi.h b/arch/x86/include/asm/asi.h index 64c2b4d1dba2..f69e1f2f09a4 100644 --- a/arch/x86/include/asm/asi.h +++ b/arch/x86/include/asm/asi.h @@ -51,7 +51,7 @@ int asi_register_class(const char *name, uint flags, const struct asi_hooks *ops); void asi_unregister_class(int index); -int asi_init(struct mm_struct *mm, int asi_index); +int asi_init(struct mm_struct *mm, int asi_index, struct asi **out_asi); void asi_destroy(struct asi *asi); void asi_enter(struct asi *asi); diff --git a/arch/x86/mm/asi.c b/arch/x86/mm/asi.c index ca50a32ecd7e..58d1c532274a 100644 --- a/arch/x86/mm/asi.c +++ b/arch/x86/mm/asi.c @@ -207,11 +207,13 @@ static int __init asi_global_init(void) } subsys_initcall(asi_global_init) -int asi_init(struct mm_struct *mm, int asi_index) +int asi_init(struct mm_struct *mm, int asi_index, struct asi **out_asi) { struct asi *asi = &mm->asi[asi_index]; - if (!boot_cpu_has(X86_FEATURE_ASI)) + *out_asi = NULL; + + if (!boot_cpu_has(X86_FEATURE_ASI) || !mm->asi_enabled) return 0; /* Index 0 is reserved for special purposes. */ @@ -238,13 +240,15 @@ int asi_init(struct mm_struct *mm, int asi_index) set_pgd(asi->pgd + i, asi_global_nonsensitive_pgd[i]); } + *out_asi = asi; + return 0; } EXPORT_SYMBOL_GPL(asi_init); void asi_destroy(struct asi *asi) { - if (!boot_cpu_has(X86_FEATURE_ASI)) + if (!boot_cpu_has(X86_FEATURE_ASI) || !asi) return; asi_free_pgd(asi); @@ -278,11 +282,9 @@ void __asi_enter(void) void asi_enter(struct asi *asi) { - if (!static_cpu_has(X86_FEATURE_ASI)) + if (!static_cpu_has(X86_FEATURE_ASI) || !asi) return; - VM_WARN_ON_ONCE(!asi); - this_cpu_write(asi_cpu_state.target_asi, asi); barrier(); @@ -423,7 +425,7 @@ int asi_map_gfp(struct asi *asi, void *addr, size_t len, gfp_t gfp_flags) size_t end = start + len; size_t page_size; - if (!static_cpu_has(X86_FEATURE_ASI)) + if (!static_cpu_has(X86_FEATURE_ASI) || !asi) return 0; VM_BUG_ON(start & ~PAGE_MASK); @@ -514,7 +516,7 @@ void asi_unmap(struct asi *asi, void *addr, size_t len, bool flush_tlb) size_t end = start + len; pgtbl_mod_mask mask = 0; - if (!static_cpu_has(X86_FEATURE_ASI) || !len) + if (!static_cpu_has(X86_FEATURE_ASI) || !asi || !len) return; VM_BUG_ON(start & ~PAGE_MASK); diff --git a/include/asm-generic/asi.h b/include/asm-generic/asi.h index f918cd052722..51c9c4a488e8 100644 --- a/include/asm-generic/asi.h +++ b/include/asm-generic/asi.h @@ -33,7 +33,12 @@ static inline void asi_unregister_class(int asi_index) { } static inline void asi_init_mm_state(struct mm_struct *mm) { } -static inline int asi_init(struct mm_struct *mm, int asi_index) { return 0; } +static inline +int asi_init(struct mm_struct *mm, int asi_index, struct asi **out_asi) +{ + *out_asi = NULL; + return 0; +} static inline void asi_destroy(struct asi *asi) { } -- 2.35.1.473.g83b2b277ed-goog