Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1953802lql; Wed, 13 Mar 2024 12:55:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhpgLZOfBQg/KGxJbj5dZOB+YGJ2CSC61lZvpQSNM5r8yPmzmT8fXj07wBaSeb34L28TtHkuyaCxgRdqX7AcQqnWwHn3wCb/rcFJOskw== X-Google-Smtp-Source: AGHT+IFiZIO5ZacCy7jEvOvHQMiMhjBX1F+5N2ktkA1QScjzxmO7/cVaUlQx+ujuvxvtHlV6DmkL X-Received: by 2002:a50:d588:0:b0:566:4624:b120 with SMTP id v8-20020a50d588000000b005664624b120mr3032695edi.26.1710359737198; Wed, 13 Mar 2024 12:55:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710359737; cv=pass; d=google.com; s=arc-20160816; b=Zga1lJqChyRyESLhTKvJICqat+DFzNMgfoaTz17kudUz67SII4X/UhzgqBRQQ2urTM 7IaNvpz8ZGWHDOK9gQmlHGkulursWBMQErtA9W4q/HQx9AvVWWOTl5KH8krSw7r0aAn9 YYFONj8lM917bBs/HdHd1y4dPX3lAJOHF5MlRRaDdGhjfXj5AjDHUyDr41VanKAROmOC uvZ/ac/it4bg31iRrIEi4AJpNJ64lFZQx/w/UxIy9iCItAW3oa4M44boMF4FjUz7ulXm vELQ9oX3IWrgYSQPQ9M10RGznqghSiqWHDnharYk6H7hBK9ZKQWAJHKt3V6YGSNX3y6C Ynzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:date:dkim-signature; bh=X5HqJNUmqWMTgd98T3K79c/2t73g8s0wifafUW041cE=; fh=ubYC+c1Y04h8QJawXr0UQ51OU7u0jSRsOGurOwVcHB8=; b=f70E+OFTOGacNZzXpDalFjfv73QxQ/8rcfr7JQfQuAUtB0j17NNmLCnDfezrcE9j1y R1C9cGW1AtCIw1CgsqAamAMwudHvzDsuGGtzu2IhCk2UlaZVclEP72GWGL1LU2faa/TX iRzfacv9KKnX+6VBrkVkp/A3afzYR8v9M05yBeImNLex2O/5KTORO3xnG5kCjagZHfDZ tAUzVVWGhUTkWVdwrosxzJnu+eFuPG0pMbCabe0D0hn6fuRLK46SSc7DYgRWG0HjvB47 7p3oIWDRJRced6AAtEv88UGLQlQ9l7wUSie9xO6CHI9C0UyC1geA2n1lzhfJuOmjfVcn hpMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UYFMEeNn; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-102455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102455-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h20-20020a50cdd4000000b00565ad309153si4903116edj.197.2024.03.13.12.55.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 12:55:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UYFMEeNn; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-102455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102455-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 am.mirrors.kernel.org (Postfix) with ESMTPS id CD68D1F24DAA for ; Wed, 13 Mar 2024 19:55:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 310955337E; Wed, 13 Mar 2024 19:55:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UYFMEeNn" Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 EDC444CB57 for ; Wed, 13 Mar 2024 19:55:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710359704; cv=none; b=vAVxiEe50ubUPQbpb9xabeh94u07I3hhy4IGjoZ9Ypl/FAKeSwESnhS64xcf+lKg0A9p21j4WX+QPlJy6JQjJ6F0NB13PfArnJqQUva+89N8hFOnsfk23zemORoC2mfvvS/NONbHXldjIEGoERWmUOVsVYlGgBotpECWTg13/68= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710359704; c=relaxed/simple; bh=vwMk2apG5ic5Dd6Bp36ZNc/3RMBxC6ECiqzJaBRCdhc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tnm5fo5gd/5bSU6WN1OeCDxYcMiQ25ozTSmng+u5aYE/MTjMYp1sbdzWkfi2a7PaaCX0plsbbWeo6KNR3lwXPXlTTiaDW2Ghi1A/t9i5ylytqL72mK/tc8AZTapDef4Vc7Zsrjd58bSfq5OJurXmS8QWVxy+LOdtq1EGoJO0MKQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UYFMEeNn; arc=none smtp.client-ip=209.85.214.202 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--seanjc.bounces.google.com Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1dd819f975aso2215425ad.3 for ; Wed, 13 Mar 2024 12:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710359702; x=1710964502; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=X5HqJNUmqWMTgd98T3K79c/2t73g8s0wifafUW041cE=; b=UYFMEeNnWADOJkURAUDkXG+5Gvi7MR8K7ewfF7AwuO9xtrThDH0lVUYE0uJcQhueji ceoSF77cnY2KX9Zhr65VN2nPCFzzxciHayFARVHmzlNP2oqDZh+7qIxgvRXOcnQoohdU K9NcbNZVltIAe5Rag42SnOPw+NwL/c0Mp3eKThBr32oFIfEVBu7hNdwlYqQIKwAUk5HZ 7xHAv6ND6KXNzluBjSfyu+ffwZJ693fzdIIwJlBW5DLlQwR/9kvNPG2FPi4H/NaJCBwz TPUjiqqBxD44wU0fse9+P53jqnMa3Wlq7fzhbGmpwikfetgFb0svVAF7L0Dzz3RXm0NY bjpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710359702; x=1710964502; h=content-transfer-encoding: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=X5HqJNUmqWMTgd98T3K79c/2t73g8s0wifafUW041cE=; b=GtXdJJ9KEtsv72q3KNn4i97UvX1UynUqR8ZHAY7K9IDbK2OK1arJ1MR9NqFiAYuF6t DHpOXq0KLtW2oAoxEB90ZDfnL02ekYubNuYEzfcUk7Ch5pT9vN5gg7Jwiwez+FbOPtpn qUsoX/he4CcNZDy4rpGxgChA1nHz3VbmCwCcVG+3ZkcUiajV1OwuGcQb7uG6HxQHkji+ /CMAerR969gzTeACobjijQycYpbr2AjtL17LgI2i1aBZ10cd+v+BG3RHIy0Etw6deKqD rd2w/ym15OPk6SlV6gojywrEl9rw351JRX95D7CezvpPRRqZ+ZxFmifDvpFxu7G9PTKZ I8Nw== X-Forwarded-Encrypted: i=1; AJvYcCXWiKddGtzn4aOZK7TL+o81PF3v3jDOVxow+dz/LGtB3orTRe93zdU5Lo39aOPKkLtRZ6UcOhH8mKvqxUR5zMV16qAcRz5vUB8P7P9k X-Gm-Message-State: AOJu0Yy4YXMxM9gJwiswNOeoiqOOihsw6l4g1ScDU2GFZrAH3D5OXSJC muIrKRjDijQrrBmISaAOUPvanlWjscasaVJ1leQ44YaTtKProTT1Fx+EIyKYQ9QIsSILVelweOb jgA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:db04:b0:1dd:8cfc:c7ee with SMTP id m4-20020a170902db0400b001dd8cfcc7eemr249385plx.11.1710359701731; Wed, 13 Mar 2024 12:55:01 -0700 (PDT) Date: Wed, 13 Mar 2024 12:55:00 -0700 In-Reply-To: <20240312173334.2484335-1-rick.p.edgecombe@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240312173334.2484335-1-rick.p.edgecombe@intel.com> Message-ID: Subject: Re: [PATCH] KVM: x86/mmu: x86: Don't overflow lpage_info when checking attributes From: Sean Christopherson To: Rick Edgecombe Cc: pbonzini@redhat.com, hao.p.peng@linux.intel.com, isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 12, 2024, Rick Edgecombe wrote: > Fix KVM_SET_MEMORY_ATTRIBUTES to not overflow lpage_info array and trigge= r > KASAN splat, as seen in the private_mem_conversions_test selftest. Ugh, that's embarrassing. > The issue can be observed simply by compiling the kernel with > CONFIG_KASAN_VMALLOC and running the selftest =E2=80=9Cprivate_mem_conver= sions_test=E2=80=9D, Ah, less emabarrasing, as KASAN_VMALLOC isn't auto-selected by KASAN=3Dy. > It is a little ambiguous whether the unaligned tail page should be Nit, it's the head page, not the tail page. Strictly speaking, it's probab= ly both (or neither, if you're a half glass empty person), but the buggy code that = is processing regions is specifically dealing with what it calls the head page= . > expected to have KVM_LPAGE_MIXED_FLAG set. It is not functionally > required, as the unaligned tail pages will already have their > kvm_lpage_info count incremented. The comments imply not setting it on > unaligned head pages is intentional, so fix the callers to skip trying to > set KVM_LPAGE_MIXED_FLAG in this case, and in doing so not call > hugepage_has_attrs(). > Also rename hugepage_has_attrs() to __slot_hugepage_has_attrs() because i= t > is a delicate function that should not be widely used, and only is valid > for ranges covered by the passed slot. Eh, I vote to drop the rename. It's (a) a local static, (b) guarded by CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES=3Dy, (c) pretty obvious from the @slot param that it works on a single slot, (d) the double underscores suggests there is an outer wrapper with the same name, which there is not, and (e) t= he rename adds noise to a diff that's destined for stable@. Other than the rename, code looks good. Thanks!