Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2101221rdd; Thu, 11 Jan 2024 21:54:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGA4CsjgGdDwMOW/d1uvH7qark008lTZYVfQVIAJoYIYGIOmxAHsGPWRqmuVgop+fpKaB8y X-Received: by 2002:ac8:5753:0:b0:429:ca11:6d70 with SMTP id 19-20020ac85753000000b00429ca116d70mr1000289qtx.44.1705038857878; Thu, 11 Jan 2024 21:54:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705038857; cv=none; d=google.com; s=arc-20160816; b=Wx/CHHsNJuKYOzT61m/sSxVLJOsslcXfUWL8IrpQR7f4Mid4nuxJY/Vfed60js4TjH uUQhQiDzInstl8qfz1MYecIyMtBb2Rt5Eu90qnw3kKDaRYGMdPfomGP9P7CTMYLCYIEg KlwSSCJO5zIhIVpSx3ZRKVHRqLgUcCW1ksmAr2CKA4quCK2JwVAvTgvi2iBwDqVnht9p G8eZFl7zRkRvtvuD6L0tCU1Xe8TZmag/xYmJDrCjSetD6yqhrOjxm8xneAnb5DwElCow vxG/wuXiPvqF9PyT6vwtk7qtE3ZnUih8S8a2fY7fGCSqGyWeJgjCshxLt/bIEUrrPEbd UBuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=MxvkESmzviEYCBtp91snCvTXp4bYwC2oMLMP2RAwiuA=; fh=f772pzXrwhuBlMr6yEvM0wkvmOz74CN31N0YtANlfBM=; b=XBoI3FKgu8J6h1pFLjDQMbNKvudKb/eKvl7GCL4NEqCqM5mX4huFsrAfjLRWx+cjfh THR6yfCf+VgRjEAyq1wbgI77lZG7ZdHQ7u/FA2fah+C//ukju0SqOcLQdNYhvWzW+5Y6 IPQiZqGBh/ctgKEPhq3da+TeoYLIip49AiNJvcag5jVBtf1L0jiruOfk76jzkZmlb9rx tC/ZFcwY5hpmUnE1pSz01vOt0iMKhejfxUBuwYUuzI/YCUoZMLbD2Dqd5VgrZIhwo6HK ocoGCvmiTY0GWONUpza9YHLVWDcMezBMAO2qgbHk2zoinc0krPCVlcb0ltx0IwaLZjIA 7rHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Z9k1mwSi; spf=pass (google.com: domain of linux-kernel+bounces-24330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24330-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y22-20020a05622a005600b00429b3b0cc79si2449896qtw.505.2024.01.11.21.54.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 21:54:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Z9k1mwSi; spf=pass (google.com: domain of linux-kernel+bounces-24330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24330-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A206F1C24D94 for ; Fri, 12 Jan 2024 05:54:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B590C5D8E6; Fri, 12 Jan 2024 05:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Z9k1mwSi" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A42585D754 for ; Fri, 12 Jan 2024 05:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vannapurve.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5e9de9795dfso116557157b3.0 for ; Thu, 11 Jan 2024 21:53:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705038795; x=1705643595; darn=vger.kernel.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=MxvkESmzviEYCBtp91snCvTXp4bYwC2oMLMP2RAwiuA=; b=Z9k1mwSi3Lrc7sKciPEyKLWtgn/dQi3Igqi+JSP+YZoi4eO+aTjh9Dd0d6+6EB80EE lxHol5Bn8YJ79P6KQjHoBGzBF4nX4nEZDLSqWMc9fkx+y7lo2SzJe9DsLZrXRTo0f346 M4gBmBmT75EIobbjPaN0TRNWod16RKAJWmtgg2Cx4jfe8iluEGCqF96krG3z8jZ6kVP/ h8aUWwzv93o1DCGlE80pI2ZVBTCG0uojo7In9TDtlmuNcJEwaTDq8PNMexaMACdePyZn k6NkCHIsRBq99NtpqLci+xKTsCnQO4ZWjaENDMNPg90JZKXvBaxwvHougTEEJ13FrF6L +Myg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705038795; x=1705643595; 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=MxvkESmzviEYCBtp91snCvTXp4bYwC2oMLMP2RAwiuA=; b=cfCHft7+FbUQ/Ym9tHJ+eaPFAl4NiHeu0TPgc82vReOePER5Xig9iD283XOG4fVbQC 1KQFVoS6X35DHETJkuFXD+uAsFwsqn5t6S9rLzIpwFQ3XqA27iduJlvtyIdl1OjeI5Zq U9EuUpAAVhsqoKgMuE4sv6blMj8bNAsB39u8oEtBxinA26EpD+BPlqVaJPzBQAfx0bZq kI9m7X6yVgH1UO/40c5fRQq2iyeqplLAoqB9r+c09y4Bo40RaWlpwnbmoQ6cpGZ1QgHU lvvaeO9FLAPcvJN6c8XXHwdxK5cgwQK5eh4jsnmy1EbH73Hr3L9iaAjFAn6xXVy5QSRs LybA== X-Gm-Message-State: AOJu0YwGAKVJYBxIND+NkQZ2QCGitbIarRKEZMDhmrB0g4dSDlvA6fIZ IXsqyGxZnXBsELS7x5K+9It6ErXeT36nNekrvXokeKU= X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:43a4]) (user=vannapurve job=sendgmr) by 2002:a0d:e003:0:b0:5fb:7d88:a558 with SMTP id j3-20020a0de003000000b005fb7d88a558mr497217ywe.0.1705038794846; Thu, 11 Jan 2024 21:53:14 -0800 (PST) Date: Fri, 12 Jan 2024 05:52:51 +0000 In-Reply-To: <20240112055251.36101-1-vannapurve@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240112055251.36101-1-vannapurve@google.com> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog Message-ID: <20240112055251.36101-6-vannapurve@google.com> Subject: [RFC V1 5/5] x86: CVMs: Ensure that memory conversions happen at 2M alignment From: Vishal Annapurve To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, rientjes@google.com, bgardon@google.com, seanjc@google.com, erdemaktas@google.com, ackerleytng@google.com, jxgao@google.com, sagis@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, pgonda@google.com, michael.roth@amd.com, kirill@shutemov.name, thomas.lendacky@amd.com, dave.hansen@linux.intel.com, linux-coco@lists.linux.dev, chao.p.peng@linux.intel.com, isaku.yamahata@gmail.com, andrew.jones@linux.dev, corbet@lwn.net, hch@lst.de, m.szyprowski@samsung.com, bp@suse.de, rostedt@goodmis.org, iommu@lists.linux.dev, Vishal Annapurve Content-Type: text/plain; charset="UTF-8" Return error on conversion of memory ranges not aligned to 2M size. Signed-off-by: Vishal Annapurve --- arch/x86/mm/pat/set_memory.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index bda9f129835e..6f7b06a502f4 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2133,8 +2133,10 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc) int ret; /* Should not be working on unaligned addresses */ - if (WARN_ONCE(addr & ~PAGE_MASK, "misaligned address: %#lx\n", addr)) - addr &= PAGE_MASK; + if (WARN_ONCE(addr & ~HPAGE_MASK, "misaligned address: %#lx\n", addr) + || WARN_ONCE((numpages << PAGE_SHIFT) & ~HPAGE_MASK, + "misaligned numpages: %#lx\n", numpages)) + return -EINVAL; memset(&cpa, 0, sizeof(cpa)); cpa.vaddr = &addr; -- 2.43.0.275.g3460e3d667-goog