Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1629902pxu; Fri, 27 Nov 2020 11:22:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJxz1kLSRNfU9f8FBafo4ym2uA5YTYrn7YO0NN8W6HWwtoqPBlIrgMV32nphGgBesPCvpDc0 X-Received: by 2002:a17:906:fa86:: with SMTP id lt6mr9325301ejb.483.1606504954216; Fri, 27 Nov 2020 11:22:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606504954; cv=none; d=google.com; s=arc-20160816; b=lcFaUoqkz9hQ2cLEExEf0iKAx7o62dzzT8FABxSbdzvEtivDGntnbdlLnojj1aGB6o GexAjZXVelNAoBlRqGm9X2MJ6hOP8lhAMh9GRZVlAEaT+wPVWaPH4+SP8QZHh/9jILJs YyDgwMikmPgvbEq1U3rTe9EB+XDvke5ZruTxqz+xxA943k6jMwk3HsmM16AFQLakr5zq MXHv47rTh3RZCqsbUke9kSd7wbXXkQh+dDkT4Ar9dvvUxfzhBjaxQNiwQ6D/k1Hz560A yEMhaSbtp4bKp8RWnw/gIYJFA4q23lqNlAlLV2v2FKDmY5m/iDRUVSbYbCxcU8wy8Bxh 4fcA== 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=ezimstzGw2as5v8kBLCxQ7oLzT/ObSdEj0HvJLvgDYA=; b=LjI7BMyjDcfEUdSZnSZJ4uBz7qs0O6WkTNqASvA19KeADo5RdycHb30Iyu9N2Yp6QZ cj4ZHwk7HqORHF0dxF2RZpkVlYoQ8Tg2fb/+ix4Ntpr4fX7GkAuMSfYHM0EYGsN1Os4N PYWKBob29miEoK+JPeNzV+68E3qO4nIW6pbZR4Fk6/a2OilWBgMbp9v32M6vnORh1jRe ZqGMbcHfhH8bsbZGf3OeLFf+yqMEwCxdvWddSdQdzUANLH8u3pLx9V2xWgxPfIUcR1Vf tsSpYE9Tc3Q2OIUZhQtdUz9Yvp6SSqIUy3Of3IEtwy/tNFo95In1LJvUmcwz6oYTB9nF 20VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZfzpzAhL; 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 h16si7206094edv.359.2020.11.27.11.21.57; Fri, 27 Nov 2020 11:22:34 -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=ZfzpzAhL; 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 S1727936AbgK0Sih (ORCPT + 99 others); Fri, 27 Nov 2020 13:38:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:34943 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727833AbgK0Sih (ORCPT ); Fri, 27 Nov 2020 13:38:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606502316; 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=ezimstzGw2as5v8kBLCxQ7oLzT/ObSdEj0HvJLvgDYA=; b=ZfzpzAhLgQGZj2odtdvKnvYKyZz+JzjUwsvVluN0IW52SOwxOofeEwW/OOOT613ck2zaxP GD5mx8iV3h6Yb1VclhfWm9FgSQRMMKbAo4+GLznaK04mQVHJx3dVdqhRaiXl2D0l+Jd2l6 gwGBS/y7oBb1REFtioQ18h1qqV/Avfg= 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-468-CTKK2xTgP3y0Zy5Rw-Isng-1; Fri, 27 Nov 2020 13:38:34 -0500 X-MC-Unique: CTKK2xTgP3y0Zy5Rw-Isng-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F85D3FD2; Fri, 27 Nov 2020 18:38:33 +0000 (UTC) Received: from idlethread.redhat.com (unknown [10.40.193.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74EB45C1C2; Fri, 27 Nov 2020 18:38:32 +0000 (UTC) From: Roberto Bergantinos Corpas To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2] sunrpc: clean-up cache downcall Date: Fri, 27 Nov 2020 19:38:31 +0100 Message-Id: <20201127183831.25012-1-rbergant@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org We can simplify code around cache_downcall unifying memory allocations using kvmalloc. This has 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 20c93b68505e..1a2c1c44bb00 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -778,7 +778,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; @@ -906,44 +905,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[32768]; /* 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