Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp469283lqd; Wed, 24 Apr 2024 07:48:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXiLIiW7E2BG1lepLg8CsYE9X9Y3joeM8axa9QiiPrGo4vjqfQ3CCImn4L1KWDgM3DIYdach3JYKWEaA2qoTBlcndOe8czeUfZv5AM3Sg== X-Google-Smtp-Source: AGHT+IFy4EumebnZwXnGScOazcczjDCCaYB2e6o/mr75G6ZkInK96q3/DJY742Pwlat7x8UcqNFs X-Received: by 2002:a9d:5e8e:0:b0:6eb:7b0e:e1e2 with SMTP id f14-20020a9d5e8e000000b006eb7b0ee1e2mr3268184otl.21.1713970105265; Wed, 24 Apr 2024 07:48:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713970105; cv=pass; d=google.com; s=arc-20160816; b=WRDYc2qM41vHJtW6JzSZ2vP1jULrjfy8i7MYZmQ257Phc5pxD1o23PU6fXgLJ4VHK3 0mFGX7yklB/oQp6FmU6Mn6g1kyPcRez1X5+YKlQV5RCaBW9FVxVPp01Y4FusUeZTwbuV oSggCjaQXPdfxO+2WJ5KRKNYVfPZT79IxHMs5OeQ5DdOHGLpErcRy0sLpC7QuRBZ50iz EaZ6gHiGfCTWc6mX1rJxQ0dy+iBvEfVCLrp/GhXNtJQ0471JqUAc98WgmyJ0ZS41Izly r9DEot655voRt5dEbpOcWtLArXM+bWaZ0AU5FuZmPVLpkrqJP6zHsx4Iao0R9apzegt6 y8FA== 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=lBUMF9M0aXotFfthPHhv12Yga6tlL0sQVtn3IgcNIjg=; fh=oovs0pRyREbRdcbZ/2f1BRlkGcINSJ2T68xMlRrMlts=; b=aBRSJoX+e4YJQU0y8QdS7tbISyMiy7+yIQ1R+y9VN+gb1KJVvPGCeelGZpW8jFqHJG DWqpKzq1KmnEYk5g8U2yAh4DHxfaRASd68JVAwcymUo8yp4egAGTxUqZIXm/TdzXoa6w jbc7Fr8lPeJIl340OOotrEs1UXvhSMvIs2Ni50zvh4LMIaEaGlA5EBJ3/zfY7KiUjtw0 AuxgJDEGowbhMAGQPUjnd/gP6fFhruktj1/aAsusJaLi8Jc0HPnnSS6pcLFPcUFv5V6G /Ogxwo+NqekvarymSPe6UaY/KLPJ44tsfqwut+NYHwCZgl3zNzzEabZlomrNpZlucXdd 6VYg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=gLHT0Dix; 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-157118-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157118-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 da32-20020a05620a362000b0078d4d321c79si14721081qkb.779.2024.04.24.07.48.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 07:48:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157118-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=gLHT0Dix; 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-157118-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157118-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 DA1351C24968 for ; Wed, 24 Apr 2024 14:48:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2FF7315F413; Wed, 24 Apr 2024 14:47:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gLHT0Dix" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 CC01415EFBE for ; Wed, 24 Apr 2024 14:47:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713970045; cv=none; b=ftLLkhCR98czljFNKcFJv2H8tZDa2TAR1u7naKvMOcXiGE/bg2Bv2UVcFMEo4FAIxllhSbCmnbL12trVQwKkqPoL6ghOPHkA6mhn8i1l/Cxg820gK5s8+j+/xgtZQ1UB1MzUccga9gaEzY1Qg8JjfdpLuZ3wKwc0ruq7YyxQJgE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713970045; c=relaxed/simple; bh=jJfd4IpFSTzCj1thfurDYFV0ttjhLiG1qEH9ToU7uvk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NW2SJwwa4Ie9cPVRVy0vHsmwNYu02gVS3J8IjPyD+iVOrJ7LIOFaLld+D8K6aiw2WoXhDNZ46RIqXYnKPthnUEZ6u2O4bCHSyBvmL45frLZUgtu6j88Ybu7/+m/bnZvK9lslhEYA8+9UplZNjuhUOA5bWy6PUSfswk7ZWvFxCnU= 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=gLHT0Dix; arc=none smtp.client-ip=209.85.128.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-yw1-f202.google.com with SMTP id 00721157ae682-618891b439eso111701537b3.3 for ; Wed, 24 Apr 2024 07:47:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713970042; x=1714574842; 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=lBUMF9M0aXotFfthPHhv12Yga6tlL0sQVtn3IgcNIjg=; b=gLHT0DixEIxV/L64q27Ss1sTGExF3Aum3m+EfcR2beLbl8Se9X1mGMXUryQayXTDFg RLMG2fWpsiR2VD11DDaq89AFocj4WUR/BSX6H0cxCS7JpzZc0SrHNGpZwfF9DbOxopJr t3oRxSCgD/tR2V4aZG55aTebrICmBqUaO+YFY4GKt36pcqOb7EIicstFYozXL8sYMru2 1d1yO2+BsT/FeNGqAkbSiD9ohhAH8bJTX6TvBpeh23aqu4Yh7UCVe3UXvqb72dUqYp99 f7r5aXvguNBRZ27ZW9Kbc2XNBaSMhJv8ZJRvTpfIdeIhcl+1N6w5xjUxbpPIC5iuE9hy PUTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713970042; x=1714574842; 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=lBUMF9M0aXotFfthPHhv12Yga6tlL0sQVtn3IgcNIjg=; b=IrfEOty4rAyjD0nSw/U7VJYDlcjy20o5zhAfi0y/VXUGdq1u3akJ7BMUAykcm6GExH 0JccLeJkz6/ox1F7ltrBYAy7GHN0AAcYIuRqaDI09tY7KsBgB7qli7ShD4B5cq3UY0sr /v8hgeWhBNJMgWyz6T1Hxs1D3SiyPR7aiO1h32g38jiYxliXdOpGQvBokM7TbfHjZvTm MdWRczkCpXuCiW3RNuSll6FiuLKakxriVN4VCQCul2H/+iMf3a2CkSTftkTvhLVOhkXn DQLweguI2Py1fQWHCj4HhdYbSzTh9YwCzisLwEaKQToo+ZCEbmhG/GBxQPYN8D028CQe Xe/A== X-Forwarded-Encrypted: i=1; AJvYcCXfBZrq6JUJTZt1Hzxy4DHlwtzih3aafreI6d9U2Sql6p3t2gE7/82ew/cfScQAQv8h55a8TcBAjrxrsW76dr97+U1sVz036p+4p3Md X-Gm-Message-State: AOJu0YyrkYeOqIiwclkjy+fwo1hwEnB3hEcV2fa60uMvNMC/0xIIAhp8 tp8Uog25PD76sADdf17N3aARhbeYkkdb7KZZrVUinBwDzb2GNVcIAFWeRUm8OORupzNJQAoHCll z8g== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1027:b0:de0:ecc6:4681 with SMTP id x7-20020a056902102700b00de0ecc64681mr234395ybt.1.1713970041911; Wed, 24 Apr 2024 07:47:21 -0700 (PDT) Date: Wed, 24 Apr 2024 07:47:20 -0700 In-Reply-To: <9f67df9d-ab27-40b9-8849-3069649dc082@moroto.mountain> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240423073952.2001989-1-chentao@kylinos.cn> <878bf83c-cd5b-48d0-8b4e-77223f1806dc@web.de> <20240423-0db9024011213dcffe815c5c@orel> <9f67df9d-ab27-40b9-8849-3069649dc082@moroto.mountain> Message-ID: Subject: Re: [PATCH] KVM: selftests: Add 'malloc' failure check in test_vmx_nested_state From: Sean Christopherson To: Dan Carpenter Cc: Andrew Jones , Markus Elfring , Kunwu Chan , linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, kernel-janitors@vger.kernel.org, Muhammad Usama Anjum , Paolo Bonzini , Shuah Khan , LKML , Kunwu Chan , Anup Patel , Thomas Huth , Oliver Upton Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 24, 2024, Dan Carpenter wrote: > On Tue, Apr 23, 2024 at 12:15:47PM -0700, Sean Christopherson wrote: > > On Tue, Apr 23, 2024, Andrew Jones wrote: > > > On Tue, Apr 23, 2024 at 07:56:01AM -0700, Sean Christopherson wrote: > > > > +others > > > >=20 > > > > On Tue, Apr 23, 2024, Markus Elfring wrote: > > > > > =E2=80=A6 > > > > > > This patch will add the malloc failure checking > > > > > =E2=80=A6 > > > > >=20 > > > > > * Please use a corresponding imperative wording for the change de= scription. > > > > >=20 > > > > > * Would you like to add the tag =E2=80=9CFixes=E2=80=9D according= ly? > > > >=20 > > > > Nah, don't bother with Fixes. OOM will cause the test to fail rega= rdless, the > > > > fact that it gets an assert instead a NULL pointer deref is nice to= have, but by > > > > no means does it fix a bug. > > > >=20 > > > > > > +++ b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_t= est.c > > > > > > @@ -91,6 +91,7 @@ void test_vmx_nested_state(struct kvm_vcpu *v= cpu) > > > > > > const int state_sz =3D sizeof(struct kvm_nested_state) + getp= agesize(); > > > > > > struct kvm_nested_state *state =3D > > > > > > (struct kvm_nested_state *)malloc(state_sz); > > > > > > + TEST_ASSERT(state, "-ENOMEM when allocating kvm state"); > > > > > =E2=80=A6 > > > > >=20 > > > > > Can =E2=80=9Cerrno=E2=80=9D be relevant for the error message con= struction? > > > >=20 > > > > Probably not, but there's also no reason to assume ENOMEM. TEST_AS= SERT() spits > > > > out the actual errno, and we can just say something like "malloc() = failed for > > > > blah blah blah". =20 > > > >=20 > > > > But rather than keeping playing whack-a-mole, what if we add macros= to perform > > > > allocations and assert on the result? I have zero interest in chas= ing down all > > > > of the "unsafe" allocations, and odds are very good that we'll coll= ectively fail > > > > to enforce checking on new code. > > > >=20 > > > > E.g. something like (obviously won't compile, just for demonstratio= n purposes) > > > >=20 > > > > #define kvm_malloc(x) > > > > ({ > > > > void *__ret; > > > >=20 > > > > __ret =3D malloc(x); > > > > TEST_ASSERT(__ret, "Failed malloc(" #x ")\n"); > > > > __ret; > > > > }) > > > >=20 > > > > #define kvm_calloc(x, y) > > > > ({ > > > > void *__ret; > > > >=20 > > > > __ret =3D calloc(x, y); > > > > TEST_ASSERT(__ret, "Failed calloc(" #x ", " #y ")\n"); > > > > __ret; > > > > }) > > >=20 > > > Sounds good to me, but I'd call them test_malloc, test_calloc, etc. a= nd > > > put them in include/test_util.h > >=20 > > Possibly terrible idea: what if we used kmalloc() and kcalloc()? K is = for KVM :-) >=20 > That's a legit terrible idea... It probably would trigger more static > checker warnings because the general policy is kmalloc() is kernel code > and we *have* to test for errors. Roger that. > To be honest, I would have just rejected the first patch. You > obviously know this and have said this earlier in the thread but just > for the other people, this is a userspace test that runs for a short > time and then exits. If it gets killed because we don't have enough > memory that's fine. It would be better to just fix the static checker > to not print pointless warnings or educate people to ignore warnings > like this. This particular patch may have been motiviated by a static checker, but I d= oubt static checkers are responsible for all of the many sanity checks on malloc= () in KVM selftests. And while I agree that the sanity checks don't and much val= ue, deleting the existing checks and preventing checks from being reintroduced = would be a never ending battle. > Creating the test_malloc() to silence the warning also seems like an > okay idea as well. Yeah, it's not exactly my first choice, but the reality is that people writ= e KVM elftests by copying an existing test (often literally), and so the best way= to educate developers on the preferred approach/style is to have all existing = code adhere to a single approach/style.