Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp762495ima; Fri, 1 Feb 2019 10:33:30 -0800 (PST) X-Google-Smtp-Source: AHgI3IZeiULYGsGqKP+V/MmA0kcY351QDlSiZvXvgKvaQucAQL4MpWt1yory/0TFSRPLhocfT+ph X-Received: by 2002:a65:64d6:: with SMTP id t22mr3024437pgv.52.1549046010553; Fri, 01 Feb 2019 10:33:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549046010; cv=none; d=google.com; s=arc-20160816; b=xmpApbJ/UqerKYRls+T+PMbufCdm2vTJL94pstDreYXWFz6GPxb+I416eF9NahKSgN nb9sy0PAP5q70GHF9q4gkJZ+32Ce/tEMdCL2JteZ/YWpsx+g69sDt7751gpzZMqKzIl5 4Anh5C/sKVJ5Du+YwtqA+nXqKG7KHhIdCy25z87HmE+/6mZaINUbNSsEzmlfstw2oP5M 9lHPDEl9SlunxMalLS5Y5mooqDbBvxRlNVdoWeLRQcM8SXpbx/4YGJdYsufKqrIi9Qtn 9pOLTetxvuRSXHdxx/Xz4obzDVYfolNa1B5NmHSSjRT3hCyEMUkyecgsm/QVFUpTFzBk KGpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=SC0lyMrasTuR9sEm02EoPwx+HkC+Cng7lP0Ta6oPNMg=; b=ArfC1vZnwfCQIl/TCtmneaHsOu5qYcP9YHE6XlJoJMYOdzeON/uDO/1Tu2PkJKnMcn +448TzNc0P/XtKbDAmHnbaJ+a+bpCsmBiQt8vILB9CiziM4nK73r4d2sF8yOrOUYpGdx s4qh2YCvIj36zJrtmxqc3FHfHSavG/g9eofVnThkZSIc89YBUa2lbxTnxrb9Nj648bAZ YWSZi+w8pht6ytXCfXguHxVV1Abylzj9DNYFMrLx6QmnXzCFHVMdzuw3RtLGwZPOOAl8 pl8yIhq32n8cJs77T5JqWuqlQ6rNeZE5hX1bIn60fJwxVx9ks1E3GtL8iBHfk7AEH8eM ihlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SSTY4UQx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b61si520455plb.70.2019.02.01.10.33.14; Fri, 01 Feb 2019 10:33:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SSTY4UQx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729455AbfBAS2w (ORCPT + 99 others); Fri, 1 Feb 2019 13:28:52 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:43629 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726017AbfBAS2v (ORCPT ); Fri, 1 Feb 2019 13:28:51 -0500 Received: by mail-ot1-f65.google.com with SMTP id a11so6812190otr.10; Fri, 01 Feb 2019 10:28:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=SC0lyMrasTuR9sEm02EoPwx+HkC+Cng7lP0Ta6oPNMg=; b=SSTY4UQxs7021+STvu0iFfLOSNEj/RdIAbdtN/Ozbmlu7+TVOQ2CtPdR82Vi/z1NpV QCrXsATH6egns4sXpo9psiWcsyr6VKbAL0d8PBGbPoLkiEYiVw2OdJQxau79xGj4Zj2L MVqiI8AoIr7Fl18OX5UWwYpT+Gd2kbLF77lytUExigZEy0zpm9CQr3yox6TC9jROLgTp TRYBoxEWYLKe2rKnW2KvzJAkIazbDUHySzovb4xxpZv2n/WH4EOmWuAD7nRbQfG4xtnV 0byUtHyTvwLi6QNt2Lk2DFrYp6cgCtMIEJS9XiS1fGZ3Gzy9F3vgG9RpHcfDhARfgXD6 Itgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=SC0lyMrasTuR9sEm02EoPwx+HkC+Cng7lP0Ta6oPNMg=; b=QJND3poOageeBJAGhrqF8eyUC/lmhJNaTts/Pigceu5jSHTb/y8kjMqGmrVkLr08vE XmNS+wkpWauK9jrNLRDyvE4ADv8fKYLZ+mA5hP1trX22HMOpSzFNFqTaRTkG//jmxkNC QeC7IoTyUHhruqPotH12cQ0BaZ9Hk0ABLXFGJ8ZQI34WN/159Fl6j8vhcDUO7ag9wqlr KnEGRv6+BgUFrU5BD0M7oBPUqJk8LdFb+J79Wr59ZfIsMUMonbgGuDlVs+pudUlAzb52 Dt2M9ZBmZZDcySskSirm+xw6EAERZ4TrR9GsIVsgfE3i96zqEY/5I06o1jSwfnVsV98T qfIA== X-Gm-Message-State: AJcUukctfs3F7gx6JnCXCzPjKi5a9/4IFei5KjCnmP2rF9iZXa5G6rPW HESZQXLE/D7FiJ1MhH3rxEV7kmXm X-Received: by 2002:a9d:4c01:: with SMTP id l1mr29826716otf.242.1549045730113; Fri, 01 Feb 2019 10:28:50 -0800 (PST) Received: from [192.168.0.2] ([98.156.228.54]) by smtp.gmail.com with ESMTPSA id t197sm3918020oif.29.2019.02.01.10.28.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Feb 2019 10:28:49 -0800 (PST) Subject: Re: [PATCH] dell_rbu: stop abusing the DMA API To: Christoph Hellwig , dvhart@infradead.org Cc: andy@infradead.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190129073409.7247-1-hch@lst.de> From: Stuart Hayes Message-ID: <4fce2a6c-2e57-bc29-0dca-8ed3bef95333@gmail.com> Date: Fri, 1 Feb 2019 12:28:46 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.0 MIME-Version: 1.0 In-Reply-To: <20190129073409.7247-1-hch@lst.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Antivirus: Avast (VPS 190131-0, 01/31/2019), Outbound message X-Antivirus-Status: Clean Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/29/2019 1:34 AM, Christoph Hellwig wrote: > For some odd reason dell_rbu actually seems to want the physical and > not a bus address for the allocated buffer. Lets assume that actually > is correct given that it is BIOS-related and that is a good source > of insanity. In that case we should not use dma_alloc_coherent with > a NULL device to allocate memory, but use GFP_DMA32 to stay under > the 32-bit BIOS limit. > > Signed-off-by: Christoph Hellwig > --- > drivers/platform/x86/dell_rbu.c | 52 ++++++++++----------------------- > 1 file changed, 15 insertions(+), 37 deletions(-) > > diff --git a/drivers/platform/x86/dell_rbu.c b/drivers/platform/x86/dell_rbu.c > index ccefa84f7305..fba7d96c1714 100644 > --- a/drivers/platform/x86/dell_rbu.c > +++ b/drivers/platform/x86/dell_rbu.c > @@ -59,7 +59,6 @@ static struct _rbu_data { > unsigned long image_update_buffer_size; > unsigned long bios_image_size; > int image_update_ordernum; > - int dma_alloc; > spinlock_t lock; > unsigned long packet_read_count; > unsigned long num_packets; > @@ -89,7 +88,6 @@ static struct packet_data packet_data_head; > > static struct platform_device *rbu_device; > static int context; > -static dma_addr_t dell_rbu_dmaaddr; > > static void init_packet_head(void) > { > @@ -380,12 +378,8 @@ static void img_update_free(void) > */ > memset(rbu_data.image_update_buffer, 0, > rbu_data.image_update_buffer_size); > - if (rbu_data.dma_alloc == 1) > - dma_free_coherent(NULL, rbu_data.bios_image_size, > - rbu_data.image_update_buffer, dell_rbu_dmaaddr); > - else > - free_pages((unsigned long) rbu_data.image_update_buffer, > - rbu_data.image_update_ordernum); > + free_pages((unsigned long) rbu_data.image_update_buffer, > + rbu_data.image_update_ordernum); > > /* > * Re-initialize the rbu_data variables after a free > @@ -394,7 +388,6 @@ static void img_update_free(void) > rbu_data.image_update_buffer = NULL; > rbu_data.image_update_buffer_size = 0; > rbu_data.bios_image_size = 0; > - rbu_data.dma_alloc = 0; > } > > /* > @@ -410,10 +403,8 @@ static void img_update_free(void) > static int img_update_realloc(unsigned long size) > { > unsigned char *image_update_buffer = NULL; > - unsigned long rc; > unsigned long img_buf_phys_addr; > int ordernum; > - int dma_alloc = 0; > > /* > * check if the buffer of sufficient size has been > @@ -444,36 +435,23 @@ static int img_update_realloc(unsigned long size) > > ordernum = get_order(size); > image_update_buffer = > - (unsigned char *) __get_free_pages(GFP_KERNEL, ordernum); > - > - img_buf_phys_addr = > - (unsigned long) virt_to_phys(image_update_buffer); > - > - if (img_buf_phys_addr > BIOS_SCAN_LIMIT) { > - free_pages((unsigned long) image_update_buffer, ordernum); > - ordernum = -1; > - image_update_buffer = dma_alloc_coherent(NULL, size, > - &dell_rbu_dmaaddr, GFP_KERNEL); > - dma_alloc = 1; > - } > - > - spin_lock(&rbu_data.lock); > - > - if (image_update_buffer != NULL) { > - rbu_data.image_update_buffer = image_update_buffer; > - rbu_data.image_update_buffer_size = size; > - rbu_data.bios_image_size = > - rbu_data.image_update_buffer_size; > - rbu_data.image_update_ordernum = ordernum; > - rbu_data.dma_alloc = dma_alloc; > - rc = 0; > - } else { > + (unsigned char *)__get_free_pages(GFP_DMA32, ordernum); > + if (!image_update_buffer) { > pr_debug("Not enough memory for image update:" > "size = %ld\n", size); > - rc = -ENOMEM; > + return -ENOMEM; > } > > - return rc; > + img_buf_phys_addr = (unsigned long)virt_to_phys(image_update_buffer); > + if (WARN_ON_ONCE(img_buf_phys_addr > BIOS_SCAN_LIMIT)) > + return -EINVAL; /* can't happen per defintion */ > + > + spin_lock(&rbu_data.lock); > + rbu_data.image_update_buffer = image_update_buffer; > + rbu_data.image_update_buffer_size = size; > + rbu_data.bios_image_size = rbu_data.image_update_buffer_size; > + rbu_data.image_update_ordernum = ordernum; > + return 0; > } > > static ssize_t read_packet_data(char *buffer, loff_t pos, size_t count) > Acked-by: Stuart Hayes