Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1443055rwl; Thu, 5 Jan 2023 13:47:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXvswn/yWnvO8nBlEPBjAogF3CYhACrlZ0HJnGCRFgkF6R7t2JbbhQh9ofx7RHxEp92UNZuY X-Received: by 2002:a17:90a:fe10:b0:226:201a:fdb0 with SMTP id ck16-20020a17090afe1000b00226201afdb0mr28771378pjb.35.1672955221360; Thu, 05 Jan 2023 13:47:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672955221; cv=none; d=google.com; s=arc-20160816; b=GcCzHDDCuKLqKzmNuD6X63EGDhGkOpcj7Z4+4PqenTsxM/xCTebRlsw2WhNQmG3Wpp +GA/xb0Yl2jUtzuiKB/IACC8vvgI9w1Dn5PcdFhCKt1X2oIXtHnjCqN49xSwIomQuddo dMpry0UgjaYfngRvYYoA/Atc5Aidmt/oH8TgDrOCSe6jk/3CJWXlhrZQv82aV169BtIx lGHJS62KG3silt2yjkf4zSMNj2wj6sNms4Tzyh+EwLv5+DVh0HgrFuDOK1XRrY4mzEoG wIT7LbV//qAvLvIQxe4VVb7VUF9M9LaUnkp/Nt/VUo5FqxkwP7SaJcSZvUf0CCQc7MRt s9rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5R84gnDXIcZCl3q1uuKNVrzE7JF/GewA0GD7Joj4Tac=; b=eviJ7Bi0oe4TPkVZhXxUYJOjpWX7YiOOtke4bx0e+yC/V4KM32AIkaSpt8SyCCft9n Gy24KRpTNBcU53iIHtFCF0tD3E4WWHmy/eCZNlVivyVL3shUZF6fsjfS3MJVQN3NuTCG MmSHDtgWCSOubvncyd29u8DJc7eeVL/S7TsOi9CRjMaIW3nlctmZiZt8rXiSLM5zPhb5 TBpZxaz+6/sZ9gvScteJccX3wEjfhEZ28dnsdI8n+rC3/UybsmqtaLpQXXTmSkOFwZta DNNWDiwga3IJuXnetPPtRofulvt1OccncBo+RAlaEAVnQzb+I6isUmiq01cNjGFQBlyq 7p2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JTqD02qz; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oj9-20020a17090b4d8900b002233101b2aesi3229862pjb.53.2023.01.05.13.46.53; Thu, 05 Jan 2023 13:47:01 -0800 (PST) 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=@google.com header.s=20210112 header.b=JTqD02qz; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235274AbjAEUiw (ORCPT + 55 others); Thu, 5 Jan 2023 15:38:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235590AbjAEUio (ORCPT ); Thu, 5 Jan 2023 15:38:44 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6F0D63F43 for ; Thu, 5 Jan 2023 12:38:42 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id z12so30973884qtv.5 for ; Thu, 05 Jan 2023 12:38:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5R84gnDXIcZCl3q1uuKNVrzE7JF/GewA0GD7Joj4Tac=; b=JTqD02qzpNL7au3Z3GUF4Xu2ARxubYVglZyPFMGjd5IBB76X21fyAUfGvELrmmzFik QzBJjZBaZ6aZe7oTAlxNCti0+kLpAukE+qZM7LrpHVjgAMiyLgJZ2+98YW1K5vKsRoVw 2umAOw9diVB8LQA7BnZCONR8pssadQA3XE8f0al71RlaiMm7wUNlcWpSs5hmEzVyjqeM eYv5U34leRc2bqLAihlC18sqPCveW9G6816ZQccg0Z2ovOthL6yQhQkI0guVnNH8iTu7 dG6eqdfXW1bD1DNzwo+oob/r+0lWSVvlcjXTltffxVApLthVRgT5BHTNgmHgdLEzU0KX YdYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5R84gnDXIcZCl3q1uuKNVrzE7JF/GewA0GD7Joj4Tac=; b=0F2P6z0dRCGWx8N44Pn6umja1tpja3iBfGLGAe+luiJyyVm60Z8nUiWAxP6MUvT7u6 oYpF+Ls9v+LyYS3nZkwG2gmY9eWUYTSMJqOFDWq+fEu2NHWqebaYQXzY2GE53w8iey5+ QVuwZ6ZIiTIv36yMkUErXMvBZaJ1h9rgvZvJqFh0/Uz+4KvocmbUGguWLcm01rccbhd5 VJC5BFi0WJOzRlTACn/BycDv9jg+j4E18jItjNF1kSBqOJWN6is4QwMypDSiKCzp+Iug 1vPFjNSqY7Xs9JgLb+U2e3Q1YJ19AUxK/OhzvI7tjC45l+hoeDLkx3/ekAXyRpOiK/mD Ai0A== X-Gm-Message-State: AFqh2kprHB0yDGZIN2NhAlOVjJIgu7MHo1asDSuqgg3lG7wdwbLZ44PB eLLDWhGkjBVOk6ypGHqLOLY7bC0ImVIDhkEdhvtnmA== X-Received: by 2002:ac8:5e0c:0:b0:3ab:754e:f0b3 with SMTP id h12-20020ac85e0c000000b003ab754ef0b3mr2062105qtx.583.1672951121587; Thu, 05 Jan 2023 12:38:41 -0800 (PST) MIME-Version: 1.0 References: <20221202061347.1070246-1-chao.p.peng@linux.intel.com> <20221202061347.1070246-10-chao.p.peng@linux.intel.com> In-Reply-To: <20221202061347.1070246-10-chao.p.peng@linux.intel.com> From: Vishal Annapurve Date: Thu, 5 Jan 2023 12:38:30 -0800 Message-ID: Subject: Re: [PATCH v10 9/9] KVM: Enable and expose KVM_MEM_PRIVATE To: Chao Peng Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Arnd Bergmann , Naoya Horiguchi , Miaohe Lin , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , tabba@google.com, Michael Roth , mhocko@suse.com, wei.w.wang@intel.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 On Thu, Dec 1, 2022 at 10:20 PM Chao Peng wrote: > > +#ifdef CONFIG_HAVE_KVM_RESTRICTED_MEM > +static bool restrictedmem_range_is_valid(struct kvm_memory_slot *slot, > + pgoff_t start, pgoff_t end, > + gfn_t *gfn_start, gfn_t *gfn_end) > +{ > + unsigned long base_pgoff = slot->restricted_offset >> PAGE_SHIFT; > + > + if (start > base_pgoff) > + *gfn_start = slot->base_gfn + start - base_pgoff; There should be a check for overflow here in case start is a very big value. Additional check can look like: if (start >= base_pgoff + slot->npages) return false; > + else > + *gfn_start = slot->base_gfn; > + > + if (end < base_pgoff + slot->npages) > + *gfn_end = slot->base_gfn + end - base_pgoff; If "end" is smaller than base_pgoff, this can cause overflow and return the range as valid. There should be additional check: if (end < base_pgoff) return false; > + else > + *gfn_end = slot->base_gfn + slot->npages; > + > + if (*gfn_start >= *gfn_end) > + return false; > + > + return true; > +} > +