Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp19864586rwd; Wed, 28 Jun 2023 15:48:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5jqwdyMCIm3WDJ4SYTPaQODF24VZCQD3boXPzq6kSFAo3245GN18cjMhRnn5ZmfMN18mer X-Received: by 2002:a17:902:a70a:b0:1b5:39f8:b22 with SMTP id w10-20020a170902a70a00b001b539f80b22mr8425976plq.33.1687992507768; Wed, 28 Jun 2023 15:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687992507; cv=none; d=google.com; s=arc-20160816; b=qmDm82hGWRekLFkGEqu2oonW5c4qKVRcF4X4siA8Zj+nUgmY38Y1TozMSehZya4A8f gVfVtsb2W3jLU3FrtHqqp8+N2pt2VqXN2wA81TBR583w1KtBEhqqgCg7V+0PchfssbeH uf9nnvhsYCf4BsGg/jjCjtWplBsBEetsSlVGLhSK8NuFFzeFMkPPcBqrZsuCaFM1WZjt tcXaj5GBw+1BFcgP72XKrh5UFqjtWma6vnQCYaRU+SuEVWTeuiO7HzxvsO1tZrFhGNDJ dxh+b4eq/YAckiPPBzu+DawgFnQYo+2zVs4kYC38ciQZVx8AdC9huYxGAQCg2IzYJoCm Hvow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4fM/UejT0qbaGH6rocxcUOMUnOOmURuuQAFrYBVK02M=; fh=CPpRkOwF9GTwy0wtS3lMI/VOqqhYg/hdxkBimukKAqo=; b=XjXKBt319vpwD/chzmBdW6StlRGMiOpcnTqGj6vGf2QYzMq9kpcACVsWY4IhMBLdiv z/0zsuj9wat0cqfm/+DcDeLgocaCSrEoTwhZxBZkXWX3gx6sjkfDcETdeepXgc5eXpMT 2794ECvsjqJ6ezBxK5fFwLMx2By89Fr5kTB8SufEpPr0vYkh3J6GkYEQcVpXYfKhB7pw SCF4odd65cr37GzTvSJQczKqmCDsBx/8YH/n2ukAGwtEnx6o9f85nFz7hXBMldD4Ymwd F8T3bi52i98K64F3KXkF6Ctltf+WklSNsVAqfHZ9qPI4eN28DZ52R3DU7lzaGKAx0xlQ T/sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iApbV70i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o4-20020a170902d4c400b001adbfba9c29si10204926plg.409.2023.06.28.15.48.14; Wed, 28 Jun 2023 15:48:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iApbV70i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232364AbjF1Wo5 (ORCPT + 99 others); Wed, 28 Jun 2023 18:44:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231493AbjF1Wn1 (ORCPT ); Wed, 28 Jun 2023 18:43:27 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1B3F2718; Wed, 28 Jun 2023 15:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687992205; x=1719528205; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6umfemwMrYz7WsXi1NlQUufCvU391Sg+THAWamuc+xA=; b=iApbV70icuAbdT/5dIrjojSKpNPuTyJJ4R2J4ZJR2jDJdWjiR53zQhI1 lTT3XZqi4AERoQmOB8DTTDZR0T2+JwkBrGaQZmFqr0p62yNt7fnnCqBuJ cRkDkAduMul4IdKXFE0GO8zLDKKQD1sUwZROeJHwdxra7tq1jFtzS66Xx 6iKQhbpI2Q55XhMUSpv/figvEtRgUUUoezCJ3KfllsfZedk/7j/8nP+t4 X/7durnmWT3F2RijVbnSgAPwwOLF0CX6VYCXIC4sms9bTGHAbTH2R68gl er00vDvW+k4OcyfcGYmEi76O2UOcbXymrZLgIYr6qPtR2ElZZgLvjsXjP Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="392699165" X-IronPort-AV: E=Sophos;i="6.01,166,1684825200"; d="scan'208";a="392699165" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 15:43:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="830300010" X-IronPort-AV: E=Sophos;i="6.01,166,1684825200"; d="scan'208";a="830300010" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 15:43:24 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, linux-coco@lists.linux.dev, Chao Peng , Ackerley Tng , Vishal Annapurve , Michael Roth , Yuan Yao Subject: [RFC PATCH v3 08/11] KVM: Fix set_mem_attr ioctl when error case Date: Wed, 28 Jun 2023 15:43:07 -0700 Message-Id: <358fb191b3690a5cbc2c985d3ffc67224df11cf3.1687991811.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Isaku Yamahata kvm_vm_ioctl_set_mem_attributes() discarded an error code of xa_err() unconditionally. If an error occurred at the beginning, return error. Fixes: 3779c214835b ("KVM: Introduce per-page memory attributes") Signed-off-by: Isaku Yamahata --- Changes v2 -> v3: - Newly added --- virt/kvm/kvm_main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 422d49634c56..fdef56f85174 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2423,6 +2423,7 @@ static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm, gfn_t start, end; unsigned long i; void *entry; + int err = 0; /* flags is currently not used. */ if (attrs->flags) @@ -2447,14 +2448,17 @@ static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm, KVM_MMU_UNLOCK(kvm); for (i = start; i < end; i++) { - if (xa_err(xa_store(&kvm->mem_attr_array, i, entry, - GFP_KERNEL_ACCOUNT))) + err = xa_err(xa_store(&kvm->mem_attr_array, i, entry, + GFP_KERNEL_ACCOUNT)); + if (err) break; } KVM_MMU_LOCK(kvm); - if (i > start) + if (i > start) { + err = 0; kvm_mem_attrs_changed(kvm, attrs->attributes, start, i); + } kvm_mmu_invalidate_end(kvm); KVM_MMU_UNLOCK(kvm); @@ -2463,7 +2467,7 @@ static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm, attrs->address = i << PAGE_SHIFT; attrs->size = (end - i) << PAGE_SHIFT; - return 0; + return err; } #endif /* CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES */ -- 2.25.1