From patchwork Thu Mar 7 13:39:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13585601 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 2E76EC54798 for ; Thu, 7 Mar 2024 13:39:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FCFF6B0183; Thu, 7 Mar 2024 08:39:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 49F116B0185; Thu, 7 Mar 2024 08:39:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20A996B0186; Thu, 7 Mar 2024 08:39:27 -0500 (EST) 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 F3C3D6B0183 for ; Thu, 7 Mar 2024 08:39:26 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D3A9C1C1342 for ; Thu, 7 Mar 2024 13:39:26 +0000 (UTC) X-FDA: 81870349932.30.DA40824 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf22.hostedemail.com (Postfix) with ESMTP id 1783DC0012 for ; Thu, 7 Mar 2024 13:39:24 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Kp2YoqoH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 3jMPpZQoKCO8pfjipRYdVUXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3jMPpZQoKCO8pfjipRYdVUXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709818765; 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=Y+p7lwWPK4A+HxnQYYFVMxpxfoiERHBbI1OMhXMl4tc=; b=0l9AZDyuJ6/usXjjW+0Gedx+Y7gvFMCQjVHycuXF43k/seuU8tBXZ0BjQWe1c80m60nBNq kmwehHToKeRbW94EjpJvrluaL843LDAuswpq1We0h1UJ8okvdiIgZ5pqjW/3VQUWOsilCu OElkwyryDwI9KxFHuJw3iO2vVYG0dF4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Kp2YoqoH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 3jMPpZQoKCO8pfjipRYdVUXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3jMPpZQoKCO8pfjipRYdVUXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709818765; a=rsa-sha256; cv=none; b=E8MvenQcMMRCNqOz5lB05m5P7XGFcOOwnmOkvwNiyNsZXZcg9+aPd6WWHpuCesWwuivu1Y 00Dk6diOdcdru+M8NBhQxtE68oQqkW27f0Rsjs972weKjHZqD83f/lZblHEYb6Lw8fWXgF bH7oYzA5qj0Hc9j4kEg8dtiUTTU/4mI= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc693399655so1648059276.1 for ; Thu, 07 Mar 2024 05:39:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709818764; x=1710423564; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Y+p7lwWPK4A+HxnQYYFVMxpxfoiERHBbI1OMhXMl4tc=; b=Kp2YoqoH6W94NuhDCHGZOl8a5bI4sc18VEODCPOO+jhk0OA319YRPLL34W0xHs+cJz mFR0f2MMlWEMgsjaYg/V8M4GPZTy1yyaexBkxxBlkkG7xFUux+l9RcrfgEHWu90ze7Jy 7oRld7ePeA4hYpcxIWIW3/IPPs3pGKSWVX4LJiIAOWtWrRuYWRBKuYUJLY1i0UlRvjb0 WY4s2XPaVppmFvRCelWG8l03kHauLN4XxUnHFM06r+QyeVijdZnkLupFdcSZ18ey+hkM 3RXcMYn92GJqBJ/6+YoDBhrXqDS3jh20AmOLvto9IbR9NQx32eM6K53flq+heErzqK8O 1UUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709818764; x=1710423564; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Y+p7lwWPK4A+HxnQYYFVMxpxfoiERHBbI1OMhXMl4tc=; b=wPog8i0mPZnjekjiDeExSg6tLL0Su7bud6dhr3r3a1T9WGYgO7AQYd99ibuypr8Hau rztnsmNtvHDox3uQ/H3Gx9KOLZsT7auZDBiBS9qKOuv2QZcAcVcABhU37KcJs3YLHCdN pi0iKAaJnbbZPgP3+8GR/mu7UJFZ0LAXSL2PjVsPUa9wnj1hbr36Xu6ZD+0rBVurgT3E 883iD7X96F0+VnLfUqoV2XKr3h1cFhwxidJyvrikqWIJ8GN1LGm7H9K6cjulOHHPliQp Bmn+EPceFjXRh8SH3F0KGvS3e6Yr6D4oi8zFSY6CMaWY80XTUfsM5VKtTtqLfwVauzS1 aO0g== X-Forwarded-Encrypted: i=1; AJvYcCVbVQEMoGE2Q0Gth+Z79izM2cZYI74WJBM2ilBQ600M41vudSimTWVXbuIbrjFZWmVQN1qS9YVoGC7DyyCLBQherdY= X-Gm-Message-State: AOJu0Yz4F/dHeDNntQJwqAJIn6EIoiAvk7wB/LMt/TnP4KffYE+dnK3S fzaOqf8rVHbLrpDoCuSnL1PZ/pWrslD1f6f6veA3vOndz6QWnOiffoqP/mQf9L9gIq3M6hCULpa zAHFaFYdfWYMi6ei2wg== X-Google-Smtp-Source: AGHT+IERxGCOOgtmKs7Ul3o8yNM4OeKiruullY93iXEMk4G4tg4OgAxxdrUv6OMg9noyhQpJciR8PQuPntNjh18q X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:1243:b0:dcf:b5b8:f825 with SMTP id t3-20020a056902124300b00dcfb5b8f825mr4599717ybu.0.1709818764114; Thu, 07 Mar 2024 05:39:24 -0800 (PST) Date: Thu, 7 Mar 2024 13:39:16 +0000 In-Reply-To: <20240307133916.3782068-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240307133916.3782068-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240307133916.3782068-4-yosryahmed@google.com> Subject: [RFC PATCH 3/3] x86/mm: cleanup prctl_enable_tagged_addr() nr_bits error checking From: Yosry Ahmed To: Andrew Morton Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Peter Zijlstra , Andy Lutomirski , "Kirill A. Shutemov" , x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: 1783DC0012 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 6nhpodr3p34wui8797gu6yqskry73zwf X-HE-Tag: 1709818764-832947 X-HE-Meta: U2FsdGVkX1+gu47jX6OH+zJ9HiaYE8Y7KuMfICj4iaN7yCJEhoIae5iTxEiI1ErPlPHRxWe5PGHordc8jTz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xTi0928jtEbMfPXfI5qbSvWAiwr2Q3G4eEJGMhjkNgUtGOgBUND7PE0sRDtLszqmPXYxzF06qQ6vwBf1p/XTyWwBP/FF/piP1d0zRW0c5+/1PwLDwV9Be/OK2uKy00gS4UnFJ5RA/Hk/U+2JiPwvMmabUX3K+La0VYSfsb8ZeWNHmPZ8wwkOubRRtpZ3/PspnYiwZJXZ+OuEfb2xIvCg/zc7v8r+wu0VBgProb4o+z4viRoSh4zRwGgrzizFno9wXu/B5GgiZi7XikI4lNpCEOQR52nU2/a9Sm4NFS3h/YDbxoBpS20yMxyxhGN6vkO5tuJylCPpgyCwleSPsRcJi6rn/vxqvgInDv0/uko8q3+N4+51ozB+OXiMS5qLe8zvpUu2tKumObQ164R/3Mr8aPocQO2NLOGNIAnU0Eu33efAHrFlOWqlNDHscCV5yQR1nRjlXAOLMd8NBtriWof+RYD8++h36qHoJPuBJjUsGO/fi1BGCbHIDVYt+h31I6baW+WMtZtfeqd/TwTbP8JA== 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: In prctl_enable_tagged_addr(), we check that nr_bits is in the correct range, but we do so in a twisted if/else block where the correct case is sandwiched between two error cases doing exactly the same thing. Simplify the if condition and pull the correct case outside with the rest of the success code path. Signed-off-by: Yosry Ahmed --- arch/x86/kernel/process_64.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 33b268747bb7b..3f381906bbe1d 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -771,17 +771,13 @@ static int prctl_enable_tagged_addr(struct mm_struct *mm, unsigned long nr_bits) return -EBUSY; } - if (!nr_bits) { - mmap_write_unlock(mm); - return -EINVAL; - } else if (nr_bits <= LAM_U57_BITS) { - mm->context.lam_cr3_mask = X86_CR3_LAM_U57; - mm->context.untag_mask = ~GENMASK(62, 57); - } else { + if (!nr_bits || nr_bits > LAM_U57_BITS) { mmap_write_unlock(mm); return -EINVAL; } + mm->context.lam_cr3_mask = X86_CR3_LAM_U57; + mm->context.untag_mask = ~GENMASK(62, 57); write_cr3(__read_cr3() | mm->context.lam_cr3_mask); set_tlbstate_lam_mode(mm); set_bit(MM_CONTEXT_LOCK_LAM, &mm->context.flags);