Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp715318pxb; Fri, 13 Aug 2021 04:54:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaMTUmXifDJJiJuiHsJuo+eEg/W1Hu5tbRPgT9EXYtKMtQv+NLCdsbPJB87e6ZXqnRZrzt X-Received: by 2002:a05:6638:43:: with SMTP id a3mr1879475jap.133.1628855686283; Fri, 13 Aug 2021 04:54:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628855686; cv=none; d=google.com; s=arc-20160816; b=vaFgdai8Cf7RCMJB8tKcn29yP1cQtll5Kt0f53B4AJGAst4EcH4x3bCX+ZIDUYyK31 rt0T4g0oaXL4lnDKU6kvABHA9Oo5l7AO2SPA4+SB7G0aV7eLw07StAyYAlSRVVPgpADy NDF5bAGb+Z5Ma8BjyuLHEIeaPwbiepxiJMz4ziesGtXvxP19TH1vWQ21tHUeECb+ZXzQ /1+/NFVMdRlajrn8pabHnjBBjcxRtuvMSRLGIPt5U/tLgvJi8rbTDZGWs+iQYUkCwjx4 UAixPW5dXwPLnjVoESMN/uWualfEOvvQ1nneqQ2iEXQPn+IWEpRxPXp241+RW3hg9r1X Q3lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=HYwYi/tWYFvYOgPwpcl7O64TbvGcPVDmi9sl6S9rSN8=; b=MOqqLdD9IZOEOHp0ENxeQs1J4fgVZA1/Ajl7drjdN/7f3Pz9JeBPveppThpbXfYfHH v0NQQasenQmLUXVtNlGYgsseL3aPLRECI6fR4mjtR4mJHd5oqd6RvXVRnPiCtMUc0xJK zyW/DM1yL8aE8dazbokdfE9OW4B3POZawaOtoz/TieI50jHHpGxASGlA11d9Jj1N+6wg m8xGN0XpKWnknOd+5VIRT/ZcjS0p3j17CG//WWNIHVFcfbX0KCeE7shXdZWaW7jrkvXz sdAtIE0Zob4KZFa3yjzUKSlqJjqaWH9guTYutsH7D05pvLSdOW+OZLitne2/Xm/m5NOZ psfQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r8si1241921jar.122.2021.08.13.04.54.35; Fri, 13 Aug 2021 04:54:46 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240314AbhHML1t (ORCPT + 99 others); Fri, 13 Aug 2021 07:27:49 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:5435 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234969AbhHML1s (ORCPT ); Fri, 13 Aug 2021 07:27:48 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R601e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0UitBNND_1628854029; Received: from B-LB6YLVDL-0141.local(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0UitBNND_1628854029) by smtp.aliyun-inc.com(127.0.0.1); Fri, 13 Aug 2021 19:27:10 +0800 Subject: Re: [PATCH v6 1/2] tty: hvc: pass DMA capable memory to put_chars() To: Greg KH Cc: jirislaby@kernel.org, amit@kernel.org, arnd@arndb.de, osandov@fb.com, linuxppc-dev@lists.ozlabs.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20210812094532.145497-1-xianting.tian@linux.alibaba.com> <20210812094532.145497-2-xianting.tian@linux.alibaba.com> From: Xianting TIan Message-ID: Date: Fri, 13 Aug 2021 19:27:09 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/8/13 下午3:27, Greg KH 写道: > On Thu, Aug 12, 2021 at 05:45:31PM +0800, Xianting Tian wrote: >> As well known, hvc backend can register its opertions to hvc backend. >> the opertions contain put_chars(), get_chars() and so on. >> >> Some hvc backend may do dma in its opertions. eg, put_chars() of >> virtio-console. But in the code of hvc framework, it may pass DMA >> incapable memory to put_chars() under a specific configuration, which >> is explained in commit c4baad5029(virtio-console: avoid DMA from stack): >> 1, c[] is on stack, >> hvc_console_print(): >> char c[N_OUTBUF] __ALIGNED__; >> cons_ops[index]->put_chars(vtermnos[index], c, i); >> 2, ch is on stack, >> static void hvc_poll_put_char(,,char ch) >> { >> struct tty_struct *tty = driver->ttys[0]; >> struct hvc_struct *hp = tty->driver_data; >> int n; >> >> do { >> n = hp->ops->put_chars(hp->vtermno, &ch, 1); >> } while (n <= 0); >> } >> >> Commit c4baad5029 is just the fix to avoid DMA from stack memory, which >> is passed to virtio-console by hvc framework in above code. But I think >> the fix is aggressive, it directly uses kmemdup() to alloc new buffer >> from kmalloc area and do memcpy no matter the memory is in kmalloc area >> or not. But most importantly, it should better be fixed in the hvc >> framework, by changing it to never pass stack memory to the put_chars() >> function in the first place. Otherwise, we still face the same issue if >> a new hvc backend using dma added in the furture. >> >> We make 'char c[N_OUTBUF]' part of 'struct hvc_struct', so hp->c is no >> longer the stack memory. we can use it in above two cases. >> >> Other fix is use L1_CACHE_BYTES as the alignment, use 'sizeof(long)' as >> dma alignment is wrong. And use struct_size() to calculate size of >> hvc_struct. >> >> Introduce another array(cons_outbuf[]) for the hp->c pointers next to >> the cons_ops[] and vtermnos[] arrays. >> >> With the patch, we can remove the fix c4baad5029. >> >> Signed-off-by: Xianting Tian >> Tested-by: Xianting Tian > As the build shows, you obviously did not test this code :( > > Also, no need to add a tested-by line as that should be implicit if you > wrote and signed off on it. > > I am going to ask you to get some help from some other developers at > your company, and get them to test and sign off on this series before > sending it out again, as there seems to be a bit of a disconnect as to > what is actually needed to do when sending a patch for us to review. > > That is now a requirement for us to be able to take your changes here. > > thanks, Sorry for this. I tested V1-V4,  But for V6, I take it for granted that there is no problem when I just switch to use array(cons_outbuf[]).  I indeed didn't test it:( I will test it and find virtualization test expert to test again before sending next patch. > > greg k-h