Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1861170iol; Fri, 10 Jun 2022 17:12:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybEBfDvMbIvh2ByiLHBu1P7PU6pzllxR2b1gSK5APpi20Q5ZRYIqbbZbAsNgz5qt8mtmkp X-Received: by 2002:aa7:93cc:0:b0:51b:f63b:6f74 with SMTP id y12-20020aa793cc000000b0051bf63b6f74mr35710738pff.66.1654906370485; Fri, 10 Jun 2022 17:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654906370; cv=none; d=google.com; s=arc-20160816; b=tq6Y9d4yQl/PlWul0CAB/vxVjBukXJAUpKZD3l42sidYzP/O0bCFpYcr6JFSKQTsUR qR2JuBJLVXr1Y1xq/YNv3rb/GWAcL56NSjtWEmR3izT939s8ylapy3IGEyq+n4d6h9Uo FUGxSICyaj43jzO5YSof5hbYtAjVxueIv5gq90s80uAnOT5b6UhaoYTJfs0RKXjRxrEb kviJwa/4WmZiQtNKhuDZA+dnB2qoXuxVb9KLnvuOykfZF+YpE8wmB87xHlXMhzPjBnXy g3udh4hso3XrceGozWmLMtkOuGn+YVEcrrS38I1fk5A+0YHpVWwQqz/bfoNU8FgEu5vU v0UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=du9S7y8Xy10Bpst/+S6RATllP69ZxhoLR7RuoE8MzGs=; b=AmQ3IzPDgeFSxKjM5V2fV2Qwn+iNn5+uFKZxNq/dQa8Wiq03TLNXKZl52FobSIA+Gh 4NpEr7LqppsoY1bFI/XyK7xze5dSUGn5pWptQnmonahTTukQH1C4+WPw2SNzR6AZ+Yep BH7C0hzJav5vMh1Ksxc6BDWQY4NiNKk9c2ibaYwnYnzDkHwM1/D6C0WNvOWkB1gR4mP4 uzTS69QwUY+N45lQOpiC/Z+dJlpWxFTWLJGt2MuWG1e/ondhcYZynA5wWZo3Y/316GzC GNbRevQ6PQVTa4zAtYNbRsFKoh07k+xrSHAFqqc6iv0izTqHdaR5h9fvIxm2iDE4bx8m ZJsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SLkQeM+p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e10-20020a170902cf4a00b001678a65d755si807717plg.154.2022.06.10.17.12.36; Fri, 10 Jun 2022 17:12:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SLkQeM+p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351030AbiFJXgy (ORCPT + 99 others); Fri, 10 Jun 2022 19:36:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350281AbiFJXgJ (ORCPT ); Fri, 10 Jun 2022 19:36:09 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 192DF289F3B; Fri, 10 Jun 2022 16:35:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654904142; x=1686440142; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E0S7lAVxIGr1gPnTIVSUeXKWXCH1YKeQN7klBTJ1vLE=; b=SLkQeM+pzRu2w6WHLXLIPXUyfpd/IZBNY8zP+UUugK5G2QgOb6HXm463 /zO0Kb1raDEMVliWzx2FKTNhkXDJtLs+FxMtwpjA3RTENpS/lamKWZbSS d3PySVvG/KICqkQv4hip0mJ8MxJvmHeNNqCq4jOAqRsVn/ZXPVL4QU99i HTAZ8CQSQOZhu48IJwqiA9HtVLP3KGDUaAsUcNY51qLoWY/L6V73dTgBj GxIc6oujwAf7URbM5lEhIOWiEaAEM1bc87vEfIMc2Iei79PvOC2bU5F0p SNDn2/2xmSg/Z/JNPSVpKa2gkVr1QsXosjJ2TNL+FwFzahfmNn916XytE g==; X-IronPort-AV: E=McAfee;i="6400,9594,10374"; a="260896457" X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="260896457" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:40 -0700 X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="909166943" Received: from pleung-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.33.34]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:40 -0700 From: ira.weiny@intel.com To: linux-api@vger.kernel.org Cc: Ira Weiny , ahaas@chromium.org, clemensb@chromium.org, gdeepti@chromium.org, jkummerow@chromium.org, manoskouk@chromium.org, thibaudm@chromium.org, Florian Weimer , Andrew Morton , Sohil Mehta , Dave Hansen , "Aneesh Kumar K . V" , x86@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH 5/6] pkeys: Up level pkey_free() checks Date: Fri, 10 Jun 2022 16:35:32 -0700 Message-Id: <20220610233533.3649584-6-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220610233533.3649584-1-ira.weiny@intel.com> References: <20220610233533.3649584-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 From: Ira Weiny x86 is missing a hardware check for pkey support in pkey_free(). While the net result is the same (-EINVAL returned), pkey_free() has well defined behavior which will be easier to maintain in one place. For powerpc the return code is -1 rather than -EINVAL. This changes that behavior slightly but this is very unlikely to break any user space. Lift the checks for pkey_free() to the core mm code and ensure consistency with returning -EINVAL. Cc: ahaas@chromium.org Cc: clemensb@chromium.org Cc: gdeepti@chromium.org Cc: jkummerow@chromium.org Cc: manoskouk@chromium.org Cc: thibaudm@chromium.org Cc: Florian Weimer Cc: Andrew Morton Cc: linux-api@vger.kernel.org Cc: Sohil Mehta Cc: Dave Hansen Cc: Aneesh Kumar K.V Signed-off-by: Ira Weiny --- Thanks to Sohil for suggesting I mention the powerpc return value in the commit message. Also Sohil suggested changing mm_pkey_free() from int to void. This is added as a separate patch with his suggested by. --- arch/powerpc/include/asm/pkeys.h | 6 ------ arch/x86/include/asm/pkeys.h | 3 --- mm/mprotect.c | 8 ++++++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index 2c8351248793..e96aa91f817b 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -107,12 +107,6 @@ static inline int mm_pkey_alloc(struct mm_struct *mm) static inline int mm_pkey_free(struct mm_struct *mm, int pkey) { - if (!mmu_has_feature(MMU_FTR_PKEY)) - return -1; - - if (!mm_pkey_is_allocated(mm, pkey)) - return -EINVAL; - __mm_pkey_free(mm, pkey); return 0; diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h index 2e6c04d8a45b..da02737cc4d1 100644 --- a/arch/x86/include/asm/pkeys.h +++ b/arch/x86/include/asm/pkeys.h @@ -107,9 +107,6 @@ int mm_pkey_alloc(struct mm_struct *mm) static inline int mm_pkey_free(struct mm_struct *mm, int pkey) { - if (!mm_pkey_is_allocated(mm, pkey)) - return -EINVAL; - mm_set_pkey_free(mm, pkey); return 0; diff --git a/mm/mprotect.c b/mm/mprotect.c index 56d35de33725..41458e729c27 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -803,10 +803,14 @@ SYSCALL_DEFINE2(pkey_alloc, unsigned long, flags, unsigned long, init_val) SYSCALL_DEFINE1(pkey_free, int, pkey) { - int ret; + int ret = -EINVAL; + + if (!arch_pkeys_enabled()) + return ret; mmap_write_lock(current->mm); - ret = mm_pkey_free(current->mm, pkey); + if (mm_pkey_is_allocated(current->mm, pkey)) + ret = mm_pkey_free(current->mm, pkey); mmap_write_unlock(current->mm); /* -- 2.35.1