Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1488041pxu; Fri, 27 Nov 2020 08:19:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGRY/Zz/6dGspOaiIsMyk4dWNA7Od3tO2nnbepBXwJqApjl8P4bDXmKNpaQA/Xli9d1gVR X-Received: by 2002:a17:906:851:: with SMTP id f17mr7545205ejd.392.1606493942048; Fri, 27 Nov 2020 08:19:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606493942; cv=none; d=google.com; s=arc-20160816; b=NPGGqJOuo25Z2kQ++IQbP8Yq6s2AIQ16IIwoveYYUZMc9I23Uw32COs0Mgg0SKmgMr WFVE4IRkQym73HzuZJf9gkzqvBvUA6h2L1gwyP6JeL80fKvZZrgnvnYTTMZ9oh0kJTou G/kqEiBzj1qayqOT2lJSCPlkEbzRPDXqjNGufpe2+dnt4vq8CLj/9Z6HVXyDK9XgShM+ 6JkJgMZLJFcc6auJmUwogxVnp/32FQrkUkyyCcirL7mHgZdN/xFMe6a1faXHCRaU9/YQ klgRwboc0FYK0hs2QXHQjeZfodcKO0vjd+LmuwZNA52o/gzyUSkRPzwVx2EbiTmTqjtn KVHw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=yFcwV5S6mrQwdzTWXy8iZEZj8Ml0ghB9YXSLBRdSVJU=; b=NJtGZ0xFOLEGXMjz8ZNs+hQux1qUF8gyVU4CuJACWvK8MmVVlMtpU1iX6xMVnEnMvk 1SNW6ZhUr68WX+TZ2yNpRpt8ATUGoCe2iiRJwwXXHiR4oygBOcQc5R+9KOpdHiZGBhll J5HSi33ulJybNwv5wSQ9t0Z6yI/fuOsNr4lA14YvUH0BAv4ol72sEbl4Qhz9wNUqWLek dxTxXovhtBuV5AI5h1YSp0JcRRGarvmdWfc3Nhp1xDxq+BSA4XiGz9a7wYaGuYINohJO QA2Gwp3wHS7O00i3yzLu7k63Wa0j7aKC9itMIeDiAgpVzyp6n7n1OgZ4jZOxfqrPVR1V YIdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xszg79ez; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-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 b2si562730ejc.96.2020.11.27.08.18.03; Fri, 27 Nov 2020 08:19:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-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=Xszg79ez; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-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 S1731170AbgK0QO6 (ORCPT + 99 others); Fri, 27 Nov 2020 11:14:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42073 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726889AbgK0QO6 (ORCPT ); Fri, 27 Nov 2020 11:14:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606493696; 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; bh=yFcwV5S6mrQwdzTWXy8iZEZj8Ml0ghB9YXSLBRdSVJU=; b=Xszg79ezA/K2U8WGCwhbNU3t9Gsy5hqWvX/80THMSYDFR784TrL6pJ6UbCoGS76NLANmAw KWn+xv5AOK3vqfJvpY7RddPDww7LGfeHUndP7tHRtOzP8/sj6eLmbYq2bvv5oDEZtc13af PDxVeGEnN/p3eYYaE25Oh28bimoloJY= 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-334--w4ig4bJPvWKrQmv7Aztqg-1; Fri, 27 Nov 2020 11:14:54 -0500 X-MC-Unique: -w4ig4bJPvWKrQmv7Aztqg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 869BB80EDAD; Fri, 27 Nov 2020 16:14:53 +0000 (UTC) Received: from idlethread.redhat.com (unknown [10.40.193.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E9C210013C1; Fri, 27 Nov 2020 16:14:52 +0000 (UTC) From: Roberto Bergantinos Corpas To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH] sunrpc: clean-up cache downcall Date: Fri, 27 Nov 2020 17:14:51 +0100 Message-Id: <20201127161451.17922-1-rbergant@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org We can simplifly code around cache_downcall unifying memory allocations using kvmalloc, this have the benefit of getting rid of cache_slow_downcall (and queue_io_mutex), and also matches userland allocation size and limits Signed-off-by: Roberto Bergantinos Corpas --- net/sunrpc/cache.c | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index baef5ee43dbb..1347ecae9c84 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -777,7 +777,6 @@ void cache_clean_deferred(void *owner) */ static DEFINE_SPINLOCK(queue_lock); -static DEFINE_MUTEX(queue_io_mutex); struct cache_queue { struct list_head list; @@ -905,44 +904,26 @@ static ssize_t cache_do_downcall(char *kaddr, const char __user *buf, return ret; } -static ssize_t cache_slow_downcall(const char __user *buf, - size_t count, struct cache_detail *cd) -{ - static char write_buf[8192]; /* protected by queue_io_mutex */ - ssize_t ret = -EINVAL; - - if (count >= sizeof(write_buf)) - goto out; - mutex_lock(&queue_io_mutex); - ret = cache_do_downcall(write_buf, buf, count, cd); - mutex_unlock(&queue_io_mutex); -out: - return ret; -} - static ssize_t cache_downcall(struct address_space *mapping, const char __user *buf, size_t count, struct cache_detail *cd) { - struct page *page; - char *kaddr; + char *write_buf; ssize_t ret = -ENOMEM; - if (count >= PAGE_SIZE) - goto out_slow; + if (count >= 32768) { /* 32k is max userland buffer, lets check anyway */ + ret = -EINVAL; + goto out; + } - page = find_or_create_page(mapping, 0, GFP_KERNEL); - if (!page) - goto out_slow; + write_buf = kvmalloc(count + 1, GFP_KERNEL); + if (!write_buf) + goto out; - kaddr = kmap(page); - ret = cache_do_downcall(kaddr, buf, count, cd); - kunmap(page); - unlock_page(page); - put_page(page); + ret = cache_do_downcall(write_buf, buf, count, cd); + kvfree(write_buf); +out: return ret; -out_slow: - return cache_slow_downcall(buf, count, cd); } static ssize_t cache_write(struct file *filp, const char __user *buf, -- 2.21.0