Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4242592pxk; Tue, 22 Sep 2020 14:15:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyShgmU0ES/z1i8Wqw9A/D3m4v6Xpft+1jUAn8Pf2g9mI5Xt8W0HmVkm1djjblALNez7hqd X-Received: by 2002:a17:906:eb4d:: with SMTP id mc13mr7085964ejb.234.1600809300971; Tue, 22 Sep 2020 14:15:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600809300; cv=none; d=google.com; s=arc-20160816; b=1A7Ct/FJtBfUnpplR5IvFJ1s9AMvRv9qQXOE/9WnM76ttZmtpIPbyFehz6ZNpQOHdY 3prIzNIoagghjbs8otIISxGYlmRgrZrTpKGWI+DW+EUsJDcaq6bRL72QA1PukQi91Oh/ X8Pv7F9QqRY8E7kYTb6KQ30f2Ln6IUrkcwfBpe/g0GynBvs2txJYyMTrpziT+hxwP7/H 2GTIbEkAjoff4Upeorm4GAB6Ou0Geb1F/7F4ImOnCqvjQ0kFEAoXw5noQiQV79sJZ6Ft mPqrlwZvB2iPBEOiiWmg8I0+FGxTbGLmZNNGvQuoDEvo9Up+ghBxeqHkEjD3HmcMvcDQ tMCA== 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=J4J8G6o2dkeXApdrpwNMYr32HCaxlIvTLSvlampSyz8=; b=a3bEespkHWLTlSObG8EX7tVE7BGAo3vkN75MlBhf3k3Q8Isf2WQ4UhoZxuH4Viimp4 ZG6WeyVurYIGaJb6JiriDrG3icsr5st4nsNWMR38UXG/b6Lrnh5wDvQL3/vUsUG/LAA/ WT5Pqsj0xaNfGjDFngvuXp5g2Sof28DOBv8iIjc1nD5xVInyMI6jzVxcuT3Miv3Ei6ts y67tJWWYDRfP8VBjlQ7dG9X909VGnWioPLSaEgw9TmstnUbRB/OidMwyS2SXlChxjr8K oA9BKXPBYmrFH6caxKU4tLTPpwCN0l5FMDDcGh82YhSMum8siUfsVdP3sIC3LF7yhpX9 HZDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hX7BPf2Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l7si10662597edv.453.2020.09.22.14.14.35; Tue, 22 Sep 2020 14:15:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hX7BPf2Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726738AbgIVVKk (ORCPT + 99 others); Tue, 22 Sep 2020 17:10:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39804 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726615AbgIVVKk (ORCPT ); Tue, 22 Sep 2020 17:10:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J4J8G6o2dkeXApdrpwNMYr32HCaxlIvTLSvlampSyz8=; b=hX7BPf2Zf1NxrEQq7SHNhrREHoIaEzp6smhTGJikhu8jTen2lbiw/bNIexjBzMw6qQ2WGW iBiqBVkWGrR7PSAc1TZgDcJ1sszkgpZVlSFpb7ozAr7BYg7fHP85xIq/RMB5HjuhRgubAY WEyd/h0AU3vlFeSQvC2oqCEm/amXDb8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-67-9sgPgTtBPaKfihsZ6OypDQ-1; Tue, 22 Sep 2020 17:10:37 -0400 X-MC-Unique: 9sgPgTtBPaKfihsZ6OypDQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F711106F71C; Tue, 22 Sep 2020 21:10:35 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A38E5577A; Tue, 22 Sep 2020 21:10:31 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: "H. Peter Anvin" , Ingo Molnar , Borislav Petkov , Vitaly Kuznetsov , Sean Christopherson , Joerg Roedel , Paolo Bonzini , Wanpeng Li , Thomas Gleixner , linux-kernel@vger.kernel.org, Jim Mattson , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), Maxim Levitsky Subject: [PATCH v6 1/4] KVM: x86: xen_hvm_config: cleanup return values Date: Wed, 23 Sep 2020 00:10:22 +0300 Message-Id: <20200922211025.175547-2-mlevitsk@redhat.com> In-Reply-To: <20200922211025.175547-1-mlevitsk@redhat.com> References: <20200922211025.175547-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return 1 on errors that are caused by wrong guest behavior (which will inject #GP to the guest) And return a negative error value on issues that are the kernel's fault (e.g -ENOMEM) Signed-off-by: Maxim Levitsky --- arch/x86/kvm/x86.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 17f4995e80a7e..063d70e736f7f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2694,24 +2694,19 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data) u32 page_num = data & ~PAGE_MASK; u64 page_addr = data & PAGE_MASK; u8 *page; - int r; - r = -E2BIG; if (page_num >= blob_size) - goto out; - r = -ENOMEM; + return 1; + page = memdup_user(blob_addr + (page_num * PAGE_SIZE), PAGE_SIZE); - if (IS_ERR(page)) { - r = PTR_ERR(page); - goto out; + if (IS_ERR(page)) + return PTR_ERR(page); + + if (kvm_vcpu_write_guest(vcpu, page_addr, page, PAGE_SIZE)) { + kfree(page); + return 1; } - if (kvm_vcpu_write_guest(vcpu, page_addr, page, PAGE_SIZE)) - goto out_free; - r = 0; -out_free: - kfree(page); -out: - return r; + return 0; } static inline bool kvm_pv_async_pf_enabled(struct kvm_vcpu *vcpu) -- 2.26.2