Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp210425lqd; Tue, 23 Apr 2024 22:41:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUiIovp+afXGpGQghm39iyl7tx6biEAuXjk3qCmWvQCt5SJYgU2qdchVTHZWwPC/OKGy27unFYpfOgBogpmT8w3TcGeHgdNfZ1AMDjIyw== X-Google-Smtp-Source: AGHT+IEvyA/70QTjT1iYMZdsGYyQxpm9JZIuE18Xx5JZ/OJhHtAJD3xnA+xerJOxkJLWGpjqA0cJ X-Received: by 2002:ac8:7f4b:0:b0:437:97f4:3f76 with SMTP id g11-20020ac87f4b000000b0043797f43f76mr2097023qtk.2.1713937318082; Tue, 23 Apr 2024 22:41:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713937318; cv=pass; d=google.com; s=arc-20160816; b=NsKMB7CXbxTB+BPhEQQ7kaf2oUX7+VvCva9HMBYCFXIPcVBrkOez+YZ7F++SN3ubZ+ D+RLLGCX5wHWu61xX87hYw7t5UeBZFD6V9c0VI+IwQv7tcx1i1U2lGKll7m/yqmSc72a 9zWB6OFWq/dpStgIJd7m206hVhCl/z8ZPEYR5nsOunVDdcCCktkNx3eqLOkXS6kPaklI 1o8Zbw/T5sMfEhqZnONSGCOYJzTB9mFNHaSuKjTK1BMSBFIYCv8Di4OxcTS7bf/MzyYC 2rJdfMRo9FGQyXWWQ95kcSZg/Hm4SHQPjO6yhh2xZdMN5Xk4nJ00srs9vd8w7tqjLkQm lUDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2UrQ3g5twb3BBJ4fBE47g+swAJMT+h6KnPSpx3YI5X0=; fh=SR4/oMUgWVDntegT1d7SIG78esqTesOhYES3DB2IcNQ=; b=rKWbfXkAtbUFG8Ek60sHw4VrG8qLnxcNTiQ56X6f1MrzwESjubvddwisiFtknwGfmO E8XMh0t/5yUjxJjP5uplfIGzpwWLfr21xEcIm2iuXcxJykG1Zi0CaC5FlAE9K9k8BSAN mFQbSVvGRRyep5pxDMp5AwJp4pA/+xAtQb1vl9dOk+8XLrfIsH4ttmrRTWBqy1lDd9Ke nj3t/pTtRneDDKEW3QyroOsVlgLA8Z+VnUL4+Fq/uu7V5Qb8t61EMlZk+U/9IJI7gjj6 LofsHqTV+Ds4WZCUB1w/xdWfPICEjh6H/Mf29fFH1Qu55es/p3mhjHKHVvpjQ3Gzbn95 4M/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WFF4Abbs; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-156324-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156324-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id cj18-20020a05622a259200b00439f687019asi2915775qtb.733.2024.04.23.22.41.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 22:41:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156324-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WFF4Abbs; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-156324-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156324-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 CA9D41C20A32 for ; Wed, 24 Apr 2024 05:41:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 124D7156878; Wed, 24 Apr 2024 05:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WFF4Abbs" Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 A9A4E156666 for ; Wed, 24 Apr 2024 05:41:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713937306; cv=none; b=ffaQuQc3J+J/g9I9XLeb1rzuTxwv5i0uYasoWZIKqIo+gcvhKQFFCgpmHAOQCXFhgR3nIY7ZXnpyPhSkLuw5IfjGwE4xlJmDr0Bz1ovIq2g2YKBUOdGwjJbRGajYe2KD9Xoo+SWlmQ0bTN9QlZj/sP1LabkEO2uq2bDKSuhWv3g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713937306; c=relaxed/simple; bh=IyElVXqzTyQ3aKo0ohOGapMAuFHTguATuxVWkpi0DWg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZdWW2tMdpSTPzKWAMX4QibGAZ3KUaHqvPh202FmEOu9Ljj3+7xu9XSJJdfMA/enqJstEUnuKLOjNW11jLZhX6/+HUm9fdv5Hg7uH6ZKedvZLis3F6k30fgjw3W6pwbhRTTUNN8GJJGEHV71S4NtgxZBSMTqqlKU62LbUTFppL8U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=WFF4Abbs; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-346359c8785so5345465f8f.0 for ; Tue, 23 Apr 2024 22:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713937302; x=1714542102; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=2UrQ3g5twb3BBJ4fBE47g+swAJMT+h6KnPSpx3YI5X0=; b=WFF4Abbs7E16RYrXIM9ggmREHhJbrusKL6X9mFsx14GWvFMiCh6ldWscjhHj8fdzPE ywrAb//GYZmmfOFxKjCcb4rlpcQtwaKb0KKI3ByNMMNBm4Vq/USsto3jD+u6F/pu+/sp +ZDl7rQ52A/NdiSYOidzNNioSX3BEqtR0h8jWEMMwF0pupvnztvK6eWEM/kAEA1QC+fs Jrh5iamokbwh5PEz+p4sxn8eJ3ZFXrGnMxwpw68pzUjWwQOpuRlTdVDvSpwCOlYuabds mVRVTxk+bAoro99mgLOoVRAfKZiN+kr22ziT3B3Vp+qEe+MsLGL5XH9+Ndeq6g/8KjAG 0Wig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713937302; x=1714542102; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2UrQ3g5twb3BBJ4fBE47g+swAJMT+h6KnPSpx3YI5X0=; b=l/Ar6B51fumvmDvyo8SDlwrcRVukbQjqXXdH1pTYu85VgGokVynabdNsOgRppFciqa LYgYz/4Ed6xbGDLa2aBefi/BJVK0YzH03Fti2ezDLI4uaZpKMOciYSJF8tsbsrVh9Un6 ff8wO2TJPZpIbiS9NBtphUtQsjIhi685STu/JR991YMFCU77NBbPXwM0J+EllY8qo5MI jCHR7DK5q2oMzwWRtrWSsjHWtV+hmGfp96YgsZxR8sTi2C/5ivtFbiTUUsfNuQlo+vFl whQ7cYnsn/eUvK9wBOCkT1Nll3e0htLgQi5tslSQSbduncsXOcKbYqY/rHtiU8SNUzed UJ0w== X-Forwarded-Encrypted: i=1; AJvYcCXez3u+0VaMJrgFtLkLWIAGA6gwoT/j0MAjv3g0ZtnqkJiodRVu7PSoSCD54twXh1LaV0unUlDBmSyWwdjupOV+Xui5RisBDWL+WX/F X-Gm-Message-State: AOJu0YynCTO6pHcieowtct+2oN/miiOXYnOF2at2me76H/WodV+QrEaC 4fLBjH/YagZIPwulMS5JxApa2Eo77hdyWsGlys6H096SywE4VbYqzR/tf4i2by0= X-Received: by 2002:a5d:4fc4:0:b0:348:1ee3:48fa with SMTP id h4-20020a5d4fc4000000b003481ee348famr846511wrw.47.1713937301787; Tue, 23 Apr 2024 22:41:41 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id l6-20020adfa386000000b00349e2fab2a2sm16376427wrb.12.2024.04.23.22.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 22:41:41 -0700 (PDT) Date: Wed, 24 Apr 2024 08:41:36 +0300 From: Dan Carpenter To: Sean Christopherson 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 Subject: Re: [PATCH] KVM: selftests: Add 'malloc' failure check in test_vmx_nested_state Message-ID: <9f67df9d-ab27-40b9-8849-3069649dc082@moroto.mountain> References: <20240423073952.2001989-1-chentao@kylinos.cn> <878bf83c-cd5b-48d0-8b4e-77223f1806dc@web.de> <20240423-0db9024011213dcffe815c5c@orel> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 > > > > > > On Tue, Apr 23, 2024, Markus Elfring wrote: > > > > … > > > > > This patch will add the malloc failure checking > > > > … > > > > > > > > * Please use a corresponding imperative wording for the change description. > > > > > > > > * Would you like to add the tag “Fixes” accordingly? > > > > > > Nah, don't bother with Fixes. OOM will cause the test to fail regardless, 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. > > > > > > > > +++ b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c > > > > > @@ -91,6 +91,7 @@ void test_vmx_nested_state(struct kvm_vcpu *vcpu) > > > > > const int state_sz = sizeof(struct kvm_nested_state) + getpagesize(); > > > > > struct kvm_nested_state *state = > > > > > (struct kvm_nested_state *)malloc(state_sz); > > > > > + TEST_ASSERT(state, "-ENOMEM when allocating kvm state"); > > > > … > > > > > > > > Can “errno” be relevant for the error message construction? > > > > > > Probably not, but there's also no reason to assume ENOMEM. TEST_ASSERT() spits > > > out the actual errno, and we can just say something like "malloc() failed for > > > blah blah blah". > > > > > > 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 chasing down all > > > of the "unsafe" allocations, and odds are very good that we'll collectively fail > > > to enforce checking on new code. > > > > > > E.g. something like (obviously won't compile, just for demonstration purposes) > > > > > > #define kvm_malloc(x) > > > ({ > > > void *__ret; > > > > > > __ret = malloc(x); > > > TEST_ASSERT(__ret, "Failed malloc(" #x ")\n"); > > > __ret; > > > }) > > > > > > #define kvm_calloc(x, y) > > > ({ > > > void *__ret; > > > > > > __ret = calloc(x, y); > > > TEST_ASSERT(__ret, "Failed calloc(" #x ", " #y ")\n"); > > > __ret; > > > }) > > > > Sounds good to me, but I'd call them test_malloc, test_calloc, etc. and > > put them in include/test_util.h > > Possibly terrible idea: what if we used kmalloc() and kcalloc()? K is for KVM :-) 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. 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. Creating the test_malloc() to silence the warning also seems like an okay idea as well. regards, dan carpenter