Get back to me
Good day. Did you receive the business proposal I sent to you yesterday? I was waiting for your reply but I am not sure if you receive the message. If for some reason you did not receive my previous email, I can resend the message to you. Please confirm as this is very urgent and important. Regards, Ashraf. ashraf...@secsuremailer.com
Re: [PATCH 5/7] IB/hfi1: use pcie_flr instead of duplicating it
On Mon, Apr 24, 2017 at 04:35:07PM +0200, Christoph Hellwig wrote: > On Mon, Apr 24, 2017 at 02:16:31PM +, Byczkowski, Jakub wrote: > > Tested-by: Jakub Byczkowski> > Are you (and Doug) ok with queueing this up in the PCI tree? Applied this with Jakub's tested-by and Doug's ack to pci/virtualization for v4.12. This still leaves these: [PATCH 4/7] ixgbe: use pcie_flr instead of duplicating it [PATCH 6/7] crypto: qat: use pcie_flr instead of duplicating it [PATCH 7/7] liquidio: use pcie_flr instead of duplicating it I haven't seen any response to 4 and 6. Felix reported an unused variable in 7. Let me know if you'd like me to do anything with these. Bjorn
Re: [PATCH v2] crypto: arm64/sha: Add constant operand modifier to ASM_EXPORT
El Tue, Apr 25, 2017 at 07:06:30PM +0100 Ard Biesheuvel ha dit: > On 25 April 2017 at 18:39, Matthias Kaehlckewrote: > > Hi, > > > > El Tue, Apr 18, 2017 at 04:35:02PM +0100 Ard Biesheuvel ha dit: > > > >> On 18 April 2017 at 15:47, Paul Gortmaker > >> wrote: > >> > On Wed, Apr 5, 2017 at 2:34 PM, Matthias Kaehlcke > >> > wrote: > >> >> The operand is an integer constant, make the constness explicit by > >> >> adding the modifier. This is needed for clang to generate valid code > >> >> and also works with gcc. > >> > > >> > Actually it doesn't work with all gcc. I've got an older arm64 > >> > toolchain that I > >> > only use for syntax checking (and hence I don't care if it is the latest > >> > and > >> > greatest) and this commit breaks it: > >> > > >> > arch/arm64/crypto/sha1-ce-glue.c:21:2: error: invalid 'asm': invalid > >> > operand prefix '%c' > >> > asm(".globl " #sym "; .set " #sym ", %c0" :: "i"(val)); > >> > > >> > I'm currently reverting this change locally so I can continue to use the > >> > old > >> > toolchain: > >> > > >> > $ aarch64-linux-gnu-gcc --version > >> > aarch64-linux-gnu-gcc (crosstool-NG linaro-1.13.1-4.8-2013.12 - Linaro > >> > GCC 2013.11) 4.8.3 20131202 (prerelease) > >> > Copyright (C) 2013 Free Software Foundation, Inc. > >> > > >> > $ aarch64-linux-gnu-as --version > >> > GNU assembler (crosstool-NG linaro-1.13.1-4.8-2013.12 - Linaro GCC > >> > 2013.11) 2.24.0.20131220 > >> > Copyright 2013 Free Software Foundation, Inc. > >> > > >> > Maybe it is finally too old and nobody cares, but I thought it worth a > >> > mention. > >> > > >> > >> Thanks for the report. I think we care more about GCC 4.8 than about > >> Clang, which argues for reverting this patch. > >> > >> I understand these issues must be frustrating if you are working on > >> this stuff, but to me, it is not entirely obvious why we want to > >> support Clang in the first place (i.e., what does it buy you if your > >> distro/environment is not already using Clang for userland), and why > >> the burden is on Linux to make modifications to support Clang, > >> especially when it comes to GCC extensions such as inline assembly > >> syntax. > >> > >> It is ultimately up to the maintainers to decide what to do with this > >> patch, but my vote would be to revert it, especially given that the %c > >> placeholder prefix is not documented anywhere, and appears to simply > >> trigger some GCC internals that happen to do the right thing in this > >> case. > >> > >> However, the I -> i change is arguably an improvement, and considering > >> that the following > >> > >> asm("foo: .long %0" :: "i"(some value)) > >> > >> doesn't compile with clang either, I suggest you (Matthias) file a bug > >> against Clang to get this fixed, and we can propose another patch just > >> for the I->i change. > > > > I consulted with folks with more expertise in this area than myself. > > This is their analysis of the situation: > > > > "The ARM ARM specifies that the correct AArch64 instruction assembly > > syntax is to have a hash sign (#) before an immediate. > > > > It does not specify that at all: > > """ > The A64 assembly language does not require the # character to > introduce constant immediate operands, but an assembler must allow > immediate values introduced with or without the # character. ARM > recommends that an A64 disassembler outputs a # before an immediate > operand. > """ > (ARM DDI 0487A.g page C1-121) > > IOW, it only /recommends/ the # sign for *dis*assemblers. Big difference. Indeed, thanks for the clarification. > > Therefore, every time an inline assembly constraint is used that > > specifies to print an immediate (like 'i' or 'I'), the immediate > > (e.g. 42) should be printed with the hash (e.g. #42). > > > > Therefore, if you're using an immediate constraint where the hash sign > > must not be printed, you have to use the "c" operand modifier. The "c" > > operand modifier apparently got introduced to gcc after the 4.8 > > release. > > > > My problem with the %c modifier is that it is completely undocumented, > and appears in an internal GCC code generation code path. IOW, the GCC > developers could also remove it at any time (although this is highly > unlikely, of course) clang documents it, but for GCC it is only mentioned under "x86 Operand Modifiers". > > The binutils assembler and the clang integrated assembler accept > > immediates without the hash sign as a non-official extension. > > Nope. *That* is mandated by the ARM ARM, see above. > > > Some of > > the immediate constraints on gcc seem to not print out the hash sign > > either; which is why the variant in the linux kernel works with gcc. > > > > Yes, and since it is perfectly legal for the "i" constraint not to > have a #, I don't understand what the big deal is tbh. > > > In summary, it seems to me that the inline assembly with the %c0 > > operand is the correct
[PATCH v2 18/21] mmc: tmio: Make use of the new sg_map helper function
Straightforward conversion to sg_map helper. Seeing there is no cleare error path, SG_MAP_MUST_NOT_FAIL which may BUG_ON in certain cases in the future. Signed-off-by: Logan GunthorpeCc: Wolfram Sang Cc: Ulf Hansson --- drivers/mmc/host/tmio_mmc.h | 7 +-- drivers/mmc/host/tmio_mmc_pio.c | 12 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h index d0edb57..bc43eb0 100644 --- a/drivers/mmc/host/tmio_mmc.h +++ b/drivers/mmc/host/tmio_mmc.h @@ -202,17 +202,20 @@ void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i); void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i); irqreturn_t tmio_mmc_irq(int irq, void *devid); +/* Note: this function may return PTR_ERR and must be checked! */ static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg, unsigned long *flags) { + void *ret; + local_irq_save(*flags); - return kmap_atomic(sg_page(sg)) + sg->offset; + return sg_map(sg, 0, SG_KMAP_ATOMIC | SG_MAP_MUST_NOT_FAIL); } static inline void tmio_mmc_kunmap_atomic(struct scatterlist *sg, unsigned long *flags, void *virt) { - kunmap_atomic(virt - sg->offset); + sg_unmap(sg, virt, 0, SG_KMAP_ATOMIC); local_irq_restore(*flags); } diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c index a2d92f1..bbb4f19 100644 --- a/drivers/mmc/host/tmio_mmc_pio.c +++ b/drivers/mmc/host/tmio_mmc_pio.c @@ -506,6 +506,18 @@ static void tmio_mmc_check_bounce_buffer(struct tmio_mmc_host *host) if (host->sg_ptr == >bounce_sg) { unsigned long flags; void *sg_vaddr = tmio_mmc_kmap_atomic(host->sg_orig, ); + if (IS_ERR(sg_vaddr)) { + /* +* This should really never happen unless +* the code is changed to use memory that is +* not mappable in the sg. Seeing there doesn't +* seem to be any error path out of here, +* we can only WARN. +*/ + WARN(1, "Non-mappable memory used in sg!"); + return; + } + memcpy(sg_vaddr, host->bounce_buf, host->bounce_sg.length); tmio_mmc_kunmap_atomic(host->sg_orig, , sg_vaddr); } -- 2.1.4
[PATCH v2 00/21] Introduce common scatterlist map function
Changes since v1: * Rebased onto next-20170424 * Removed the _offset version of these functions per Christoph's suggestion * Added an SG_MAP_MUST_NOT_FAIL flag which will BUG_ON in future cases that can't gracefully fail. This removes a bunch of the noise added in v1 to a couple of the drivers. (Per David Laight's suggestion) This flag is only meant for old code * Split the libiscsi patch into two (per Christoph's suggestion) the prep patch (patch 2 in this series) has already been sent separately * Fixed a locking mistake in the target patch (pointed out by a bot) * Dropped the nvmet patch and handled it with a different patch that has been sent separately * Dropped the chcr patch as they have already removed the code that needed to be changed I'm still hoping to only get Patch 1 in the series merged. (Any volunteers?) I'm willing to chase down the maintainers for the remaining patches separately after the first patch is in. The patchset is based on next-20170424 and can be found in the sg_map_v2 branch from this git tree: https://github.com/sbates130272/linux-p2pmem.git -- Hi Everyone, As part of my effort to enable P2P DMA transactions with PCI cards, we've identified the need to be able to safely put IO memory into scatterlists (and eventually other spots). This probably involves a conversion from struct page to pfn_t but that migration is a ways off and those decisions are yet to be made. As an initial step in that direction, I've started cleaning up some of the scatterlist code by trying to carve out a better defined layer between it and it's users. The longer term goal would be to remove sg_page or replace it with something that can potentially fail. This patchset is the first step in that effort. I've introduced a common function to map scatterlist memory and converted all the common kmap(sg_page()) cases. This removes about 66 sg_page calls (of ~331). Seeing this is a fairly large cleanup set that touches a wide swath of the kernel I have limited the people I've sent this to. I'd suggest we look toward merging the first patch and then I can send the individual subsystem patches on to their respective maintainers and get them merged independantly. (This is to avoid the conflicts I created with my last cleanup set... Sorry) Though, I'm certainly open to other suggestions to get it merged. Logan Gunthorpe (21): scatterlist: Introduce sg_map helper functions libiscsi: Add an internal error code libiscsi: Make use of new the sg_map helper function target: Make use of the new sg_map function at 16 call sites drm/i915: Make use of the new sg_map helper function crypto: hifn_795x: Make use of the new sg_map helper function crypto: shash, caam: Make use of the new sg_map helper function dm-crypt: Make use of the new sg_map helper in 4 call sites staging: unisys: visorbus: Make use of the new sg_map helper function RDS: Make use of the new sg_map helper function scsi: ipr, pmcraid, isci: Make use of the new sg_map helper scsi: hisi_sas, mvsas, gdth: Make use of the new sg_map helper function scsi: arcmsr, ips, megaraid: Make use of the new sg_map helper function scsi: libfc, csiostor: Change to sg_copy_buffer in two drivers xen-blkfront: Make use of the new sg_map helper function mmc: sdhci: Make use of the new sg_map helper function mmc: spi: Make use of the new sg_map helper function mmc: tmio: Make use of the new sg_map helper function mmc: sdricoh_cs: Make use of the new sg_map helper function mmc: tifm_sd: Make use of the new sg_map helper function memstick: Make use of the new sg_map helper function crypto/shash.c | 9 ++- drivers/block/xen-blkfront.c| 20 ++--- drivers/crypto/caam/caamalg.c | 8 +- drivers/crypto/hifn_795x.c | 32 +--- drivers/gpu/drm/i915/i915_gem.c | 27 --- drivers/md/dm-crypt.c | 39 ++--- drivers/memstick/host/jmb38x_ms.c | 11 +-- drivers/memstick/host/tifm_ms.c | 11 +-- drivers/mmc/host/mmc_spi.c | 26 -- drivers/mmc/host/sdhci.c| 14 ++-- drivers/mmc/host/sdricoh_cs.c | 14 ++-- drivers/mmc/host/tifm_sd.c | 50 +++- drivers/mmc/host/tmio_mmc.h | 7 +- drivers/mmc/host/tmio_mmc_pio.c | 12 +++ drivers/scsi/arcmsr/arcmsr_hba.c| 16 +++- drivers/scsi/csiostor/csio_scsi.c | 54 + drivers/scsi/cxgbi/libcxgbi.c | 5 ++ drivers/scsi/gdth.c | 9 ++- drivers/scsi/hisi_sas/hisi_sas_v1_hw.c | 14 ++-- drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 13 ++- drivers/scsi/ipr.c | 27 --- drivers/scsi/ips.c | 8 +-
[PATCH v2 03/21] libiscsi: Make use of new the sg_map helper function
Convert the kmap and kmap_atomic uses to the sg_map function. We now store the flags for the kmap instead of a boolean to indicate atomicitiy. We use ISCSI_TCP_INTERNAL_ERR error type that was prepared earlier for this. Signed-off-by: Logan GunthorpeCc: Lee Duncan Cc: Chris Leech --- drivers/scsi/libiscsi_tcp.c | 32 include/scsi/libiscsi_tcp.h | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/scsi/libiscsi_tcp.c b/drivers/scsi/libiscsi_tcp.c index 63a1d69..a34e25c 100644 --- a/drivers/scsi/libiscsi_tcp.c +++ b/drivers/scsi/libiscsi_tcp.c @@ -133,25 +133,23 @@ static void iscsi_tcp_segment_map(struct iscsi_segment *segment, int recv) if (page_count(sg_page(sg)) >= 1 && !recv) return; - if (recv) { - segment->atomic_mapped = true; - segment->sg_mapped = kmap_atomic(sg_page(sg)); - } else { - segment->atomic_mapped = false; - /* the xmit path can sleep with the page mapped so use kmap */ - segment->sg_mapped = kmap(sg_page(sg)); + /* the xmit path can sleep with the page mapped so don't use atomic */ + segment->sg_map_flags = recv ? SG_KMAP_ATOMIC : SG_KMAP; + segment->sg_mapped = sg_map(sg, 0, segment->sg_map_flags); + + if (IS_ERR(segment->sg_mapped)) { + segment->sg_mapped = NULL; + return; } - segment->data = segment->sg_mapped + sg->offset + segment->sg_offset; + segment->data = segment->sg_mapped + segment->sg_offset; } void iscsi_tcp_segment_unmap(struct iscsi_segment *segment) { if (segment->sg_mapped) { - if (segment->atomic_mapped) - kunmap_atomic(segment->sg_mapped); - else - kunmap(sg_page(segment->sg)); + sg_unmap(segment->sg, segment->sg_mapped, 0, +segment->sg_map_flags); segment->sg_mapped = NULL; segment->data = NULL; } @@ -304,6 +302,9 @@ iscsi_tcp_segment_recv(struct iscsi_tcp_conn *tcp_conn, break; } + if (segment->data) + return -EFAULT; + copy = min(len - copied, segment->size - segment->copied); ISCSI_DBG_TCP(tcp_conn->iscsi_conn, "copying %d\n", copy); memcpy(segment->data + segment->copied, ptr + copied, copy); @@ -927,6 +928,13 @@ int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct sk_buff *skb, avail); rc = iscsi_tcp_segment_recv(tcp_conn, segment, ptr, avail); BUG_ON(rc == 0); + if (rc < 0) { + ISCSI_DBG_TCP(conn, "memory fault. Consumed %d\n", + consumed); + *status = ISCSI_TCP_INTERNAL_ERR; + goto skb_done; + } + consumed += rc; if (segment->total_copied >= segment->total_size) { diff --git a/include/scsi/libiscsi_tcp.h b/include/scsi/libiscsi_tcp.h index 90691ad..58c79af 100644 --- a/include/scsi/libiscsi_tcp.h +++ b/include/scsi/libiscsi_tcp.h @@ -47,7 +47,7 @@ struct iscsi_segment { struct scatterlist *sg; void*sg_mapped; unsigned intsg_offset; - boolatomic_mapped; + int sg_map_flags; iscsi_segment_done_fn_t *done; }; -- 2.1.4
[PATCH v2 14/21] scsi: libfc, csiostor: Change to sg_copy_buffer in two drivers
These two drivers appear to duplicate the functionality of sg_copy_buffer. So we clean them up to use the common code. This helps us remove a couple of instances that would otherwise be slightly tricky sg_map usages. Signed-off-by: Logan GunthorpeCc: Johannes Thumshirn --- drivers/scsi/csiostor/csio_scsi.c | 54 +++ drivers/scsi/libfc/fc_libfc.c | 49 --- 2 files changed, 14 insertions(+), 89 deletions(-) diff --git a/drivers/scsi/csiostor/csio_scsi.c b/drivers/scsi/csiostor/csio_scsi.c index a1ff75f..bd9d062 100644 --- a/drivers/scsi/csiostor/csio_scsi.c +++ b/drivers/scsi/csiostor/csio_scsi.c @@ -1489,60 +1489,14 @@ static inline uint32_t csio_scsi_copy_to_sgl(struct csio_hw *hw, struct csio_ioreq *req) { struct scsi_cmnd *scmnd = (struct scsi_cmnd *)csio_scsi_cmnd(req); - struct scatterlist *sg; - uint32_t bytes_left; - uint32_t bytes_copy; - uint32_t buf_off = 0; - uint32_t start_off = 0; - uint32_t sg_off = 0; - void *sg_addr; - void *buf_addr; struct csio_dma_buf *dma_buf; + size_t copied; - bytes_left = scsi_bufflen(scmnd); - sg = scsi_sglist(scmnd); dma_buf = (struct csio_dma_buf *)csio_list_next(>gen_list); + copied = sg_copy_from_buffer(scsi_sglist(scmnd), scsi_sg_count(scmnd), +dma_buf->vaddr, scsi_bufflen(scmnd)); - /* Copy data from driver buffer to SGs of SCSI CMD */ - while (bytes_left > 0 && sg && dma_buf) { - if (buf_off >= dma_buf->len) { - buf_off = 0; - dma_buf = (struct csio_dma_buf *) - csio_list_next(dma_buf); - continue; - } - - if (start_off >= sg->length) { - start_off -= sg->length; - sg = sg_next(sg); - continue; - } - - buf_addr = dma_buf->vaddr + buf_off; - sg_off = sg->offset + start_off; - bytes_copy = min((dma_buf->len - buf_off), - sg->length - start_off); - bytes_copy = min((uint32_t)(PAGE_SIZE - (sg_off & ~PAGE_MASK)), -bytes_copy); - - sg_addr = kmap_atomic(sg_page(sg) + (sg_off >> PAGE_SHIFT)); - if (!sg_addr) { - csio_err(hw, "failed to kmap sg:%p of ioreq:%p\n", - sg, req); - break; - } - - csio_dbg(hw, "copy_to_sgl:sg_addr %p sg_off %d buf %p len %d\n", - sg_addr, sg_off, buf_addr, bytes_copy); - memcpy(sg_addr + (sg_off & ~PAGE_MASK), buf_addr, bytes_copy); - kunmap_atomic(sg_addr); - - start_off += bytes_copy; - buf_off += bytes_copy; - bytes_left -= bytes_copy; - } - - if (bytes_left > 0) + if (copied != scsi_bufflen(scmnd)) return DID_ERROR; else return DID_OK; diff --git a/drivers/scsi/libfc/fc_libfc.c b/drivers/scsi/libfc/fc_libfc.c index d623d08..ce0805a 100644 --- a/drivers/scsi/libfc/fc_libfc.c +++ b/drivers/scsi/libfc/fc_libfc.c @@ -113,45 +113,16 @@ u32 fc_copy_buffer_to_sglist(void *buf, size_t len, u32 *nents, size_t *offset, u32 *crc) { - size_t remaining = len; - u32 copy_len = 0; - - while (remaining > 0 && sg) { - size_t off, sg_bytes; - void *page_addr; - - if (*offset >= sg->length) { - /* -* Check for end and drop resources -* from the last iteration. -*/ - if (!(*nents)) - break; - --(*nents); - *offset -= sg->length; - sg = sg_next(sg); - continue; - } - sg_bytes = min(remaining, sg->length - *offset); - - /* -* The scatterlist item may be bigger than PAGE_SIZE, -* but we are limited to mapping PAGE_SIZE at a time. -*/ - off = *offset + sg->offset; - sg_bytes = min(sg_bytes, - (size_t)(PAGE_SIZE - (off & ~PAGE_MASK))); - page_addr = kmap_atomic(sg_page(sg) + (off >> PAGE_SHIFT)); - if (crc) - *crc = crc32(*crc, buf, sg_bytes); - memcpy((char *)page_addr + (off & ~PAGE_MASK), buf, sg_bytes); - kunmap_atomic(page_addr); - buf += sg_bytes; - *offset += sg_bytes; -
[PATCH v2 04/21] target: Make use of the new sg_map function at 16 call sites
Fairly straightforward conversions in all spots. In a couple of cases any error gets propogated up should sg_map fail. In other cases a warning is issued if the kmap fails seeing there's no clear error path. This should not be an issue until someone tries to use unmappable memory in the sgl with this driver. Signed-off-by: Logan GunthorpeCc: "Nicholas A. Bellinger" --- drivers/target/iscsi/iscsi_target.c| 29 +++--- drivers/target/target_core_rd.c| 3 +- drivers/target/target_core_sbc.c | 103 + drivers/target/target_core_transport.c | 18 -- drivers/target/target_core_user.c | 45 +- include/target/target_core_backend.h | 4 +- 6 files changed, 134 insertions(+), 68 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index e3f9ed3..3ab8d21 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -578,7 +578,7 @@ iscsit_xmit_nondatain_pdu(struct iscsi_conn *conn, struct iscsi_cmd *cmd, } static int iscsit_map_iovec(struct iscsi_cmd *, struct kvec *, u32, u32); -static void iscsit_unmap_iovec(struct iscsi_cmd *); +static void iscsit_unmap_iovec(struct iscsi_cmd *, struct kvec *); static u32 iscsit_do_crypto_hash_sg(struct ahash_request *, struct iscsi_cmd *, u32, u32, u32, u8 *); static int @@ -645,7 +645,7 @@ iscsit_xmit_datain_pdu(struct iscsi_conn *conn, struct iscsi_cmd *cmd, ret = iscsit_fe_sendpage_sg(cmd, conn); - iscsit_unmap_iovec(cmd); + iscsit_unmap_iovec(cmd, >iov_data[1]); if (ret < 0) { iscsit_tx_thread_wait_for_tcp(conn); @@ -924,7 +924,10 @@ static int iscsit_map_iovec( while (data_length) { u32 cur_len = min_t(u32, data_length, sg->length - page_off); - iov[i].iov_base = kmap(sg_page(sg)) + sg->offset + page_off; + iov[i].iov_base = sg_map(sg, page_off, SG_KMAP); + if (IS_ERR(iov[i].iov_base)) + goto map_err; + iov[i].iov_len = cur_len; data_length -= cur_len; @@ -936,17 +939,25 @@ static int iscsit_map_iovec( cmd->kmapped_nents = i; return i; + +map_err: + cmd->kmapped_nents = i - 1; + iscsit_unmap_iovec(cmd, iov); + return -1; } -static void iscsit_unmap_iovec(struct iscsi_cmd *cmd) +static void iscsit_unmap_iovec(struct iscsi_cmd *cmd, struct kvec *iov) { u32 i; struct scatterlist *sg; + unsigned int page_off = cmd->first_data_sg_off; sg = cmd->first_data_sg; - for (i = 0; i < cmd->kmapped_nents; i++) - kunmap(sg_page([i])); + for (i = 0; i < cmd->kmapped_nents; i++) { + sg_unmap([i], iov[i].iov_base, page_off, SG_KMAP); + page_off = 0; + } } static void iscsit_ack_from_expstatsn(struct iscsi_conn *conn, u32 exp_statsn) @@ -1609,7 +1620,7 @@ iscsit_get_dataout(struct iscsi_conn *conn, struct iscsi_cmd *cmd, rx_got = rx_data(conn, >iov_data[0], iov_count, rx_size); - iscsit_unmap_iovec(cmd); + iscsit_unmap_iovec(cmd, iov); if (rx_got != rx_size) return -1; @@ -1710,7 +1721,7 @@ int iscsit_setup_nop_out(struct iscsi_conn *conn, struct iscsi_cmd *cmd, if (!cmd) return iscsit_add_reject(conn, ISCSI_REASON_PROTOCOL_ERROR, (unsigned char *)hdr); - + return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, (unsigned char *)hdr); } @@ -2625,7 +2636,7 @@ static int iscsit_handle_immediate_data( rx_got = rx_data(conn, >iov_data[0], iov_count, rx_size); - iscsit_unmap_iovec(cmd); + iscsit_unmap_iovec(cmd, cmd->iov_data); if (rx_got != rx_size) { iscsit_rx_thread_wait_for_tcp(conn); diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c index 5f23f34..348211c 100644 --- a/drivers/target/target_core_rd.c +++ b/drivers/target/target_core_rd.c @@ -432,7 +432,8 @@ static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, bool is_read) cmd->t_prot_sg, 0); } if (!rc) - sbc_dif_copy_prot(cmd, sectors, is_read, prot_sg, prot_offset); + rc = sbc_dif_copy_prot(cmd, sectors, is_read, prot_sg, + prot_offset); return rc; } diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index ee35c90..8ac07c6 100644 --- a/drivers/target/target_core_sbc.c +++ b/drivers/target/target_core_sbc.c @@ -420,17 +420,17 @@ static sense_reason_t xdreadwrite_callback(struct se_cmd *cmd, bool success, offset
[PATCH v2 07/21] crypto: shash, caam: Make use of the new sg_map helper function
Very straightforward conversion to the new function in the caam driver and shash library. Signed-off-by: Logan GunthorpeCc: Herbert Xu Cc: "David S. Miller" --- crypto/shash.c| 9 ++--- drivers/crypto/caam/caamalg.c | 8 +++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crypto/shash.c b/crypto/shash.c index 5e31c8d..5914881 100644 --- a/crypto/shash.c +++ b/crypto/shash.c @@ -283,10 +283,13 @@ int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc) if (nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset)) { void *data; - data = kmap_atomic(sg_page(sg)); - err = crypto_shash_digest(desc, data + offset, nbytes, + data = sg_map(sg, 0, SG_KMAP_ATOMIC); + if (IS_ERR(data)) + return PTR_ERR(data); + + err = crypto_shash_digest(desc, data, nbytes, req->result); - kunmap_atomic(data); + sg_unmap(sg, data, 0, SG_KMAP_ATOMIC); crypto_yield(desc->flags); } else err = crypto_shash_init(desc) ?: diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 398807d..62d2f5d 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -89,7 +89,6 @@ static void dbg_dump_sg(const char *level, const char *prefix_str, struct scatterlist *sg, size_t tlen, bool ascii) { struct scatterlist *it; - void *it_page; size_t len; void *buf; @@ -98,19 +97,18 @@ static void dbg_dump_sg(const char *level, const char *prefix_str, * make sure the scatterlist's page * has a valid virtual memory mapping */ - it_page = kmap_atomic(sg_page(it)); - if (unlikely(!it_page)) { + buf = sg_map(it, 0, SG_KMAP_ATOMIC); + if (IS_ERR(buf)) { printk(KERN_ERR "dbg_dump_sg: kmap failed\n"); return; } - buf = it_page + it->offset; len = min_t(size_t, tlen, it->length); print_hex_dump(level, prefix_str, prefix_type, rowsize, groupsize, buf, len, ascii); tlen -= len; - kunmap_atomic(it_page); + sg_unmap(it, buf, 0, SG_KMAP_ATOMIC); } } #endif -- 2.1.4
[PATCH v2 11/21] scsi: ipr, pmcraid, isci: Make use of the new sg_map helper
Very straightforward conversion of three scsi drivers. Signed-off-by: Logan GunthorpeCc: Brian King Cc: Artur Paszkiewicz --- drivers/scsi/ipr.c | 27 ++- drivers/scsi/isci/request.c | 42 +- drivers/scsi/pmcraid.c | 19 --- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c index b0c68d2..b2324e1 100644 --- a/drivers/scsi/ipr.c +++ b/drivers/scsi/ipr.c @@ -3895,7 +3895,7 @@ static void ipr_free_ucode_buffer(struct ipr_sglist *sglist) static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist, u8 *buffer, u32 len) { - int bsize_elem, i, result = 0; + int bsize_elem, i; struct scatterlist *scatterlist; void *kaddr; @@ -3905,32 +3905,33 @@ static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist, scatterlist = sglist->scatterlist; for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) { - struct page *page = sg_page([i]); + kaddr = sg_map([i], 0, SG_KMAP); + if (IS_ERR(kaddr)) { + ipr_trace; + return PTR_ERR(kaddr); + } - kaddr = kmap(page); memcpy(kaddr, buffer, bsize_elem); - kunmap(page); + sg_unmap([i], kaddr, 0, SG_KMAP); scatterlist[i].length = bsize_elem; - - if (result != 0) { - ipr_trace; - return result; - } } if (len % bsize_elem) { - struct page *page = sg_page([i]); + kaddr = sg_map([i], 0, SG_KMAP); + if (IS_ERR(kaddr)) { + ipr_trace; + return PTR_ERR(kaddr); + } - kaddr = kmap(page); memcpy(kaddr, buffer, len % bsize_elem); - kunmap(page); + sg_unmap([i], kaddr, 0, SG_KMAP); scatterlist[i].length = len % bsize_elem; } sglist->buffer_len = len; - return result; + return 0; } /** diff --git a/drivers/scsi/isci/request.c b/drivers/scsi/isci/request.c index 47f66e9..6f5521b 100644 --- a/drivers/scsi/isci/request.c +++ b/drivers/scsi/isci/request.c @@ -1424,12 +1424,14 @@ sci_stp_request_pio_data_in_copy_data_buffer(struct isci_stp_request *stp_req, sg = task->scatter; while (total_len > 0) { - struct page *page = sg_page(sg); - copy_len = min_t(int, total_len, sg_dma_len(sg)); - kaddr = kmap_atomic(page); - memcpy(kaddr + sg->offset, src_addr, copy_len); - kunmap_atomic(kaddr); + kaddr = sg_map(sg, 0, SG_KMAP_ATOMIC); + if (IS_ERR(kaddr)) + return SCI_FAILURE; + + memcpy(kaddr, src_addr, copy_len); + sg_unmap(sg, kaddr, 0, SG_KMAP_ATOMIC); + total_len -= copy_len; src_addr += copy_len; sg = sg_next(sg); @@ -1771,14 +1773,16 @@ sci_io_request_frame_handler(struct isci_request *ireq, case SCI_REQ_SMP_WAIT_RESP: { struct sas_task *task = isci_request_access_task(ireq); struct scatterlist *sg = >smp_task.smp_resp; - void *frame_header, *kaddr; + void *frame_header; u8 *rsp; sci_unsolicited_frame_control_get_header(>uf_control, frame_index, _header); - kaddr = kmap_atomic(sg_page(sg)); - rsp = kaddr + sg->offset; + rsp = sg_map(sg, 0, SG_KMAP_ATOMIC); + if (IS_ERR(rsp)) + return SCI_FAILURE; + sci_swab32_cpy(rsp, frame_header, 1); if (rsp[0] == SMP_RESPONSE) { @@ -1814,7 +1818,7 @@ sci_io_request_frame_handler(struct isci_request *ireq, ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; sci_change_state(>sm, SCI_REQ_COMPLETED); } - kunmap_atomic(kaddr); + sg_unmap(sg, rsp, 0, SG_KMAP_ATOMIC); sci_controller_release_frame(ihost, frame_index); @@ -2919,15 +2923,18 @@ static void isci_request_io_request_complete(struct isci_host *ihost, case SAS_PROTOCOL_SMP: { struct scatterlist *sg = >smp_task.smp_req; struct smp_req *smp_req; - void *kaddr; dma_unmap_sg(>pdev->dev, sg, 1,
[PATCH v2 21/21] memstick: Make use of the new sg_map helper function
Straightforward conversion, but we have to make use of SG_MAP_MUST_NOT_FAIL which may BUG_ON in certain cases in the future. Signed-off-by: Logan GunthorpeCc: Alex Dubov --- drivers/memstick/host/jmb38x_ms.c | 11 ++- drivers/memstick/host/tifm_ms.c | 11 ++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/memstick/host/jmb38x_ms.c b/drivers/memstick/host/jmb38x_ms.c index 48db922..9019e37 100644 --- a/drivers/memstick/host/jmb38x_ms.c +++ b/drivers/memstick/host/jmb38x_ms.c @@ -303,7 +303,6 @@ static int jmb38x_ms_transfer_data(struct jmb38x_ms_host *host) unsigned int off; unsigned int t_size, p_cnt; unsigned char *buf; - struct page *pg; unsigned long flags = 0; if (host->req->long_data) { @@ -318,14 +317,14 @@ static int jmb38x_ms_transfer_data(struct jmb38x_ms_host *host) unsigned int uninitialized_var(p_off); if (host->req->long_data) { - pg = nth_page(sg_page(>req->sg), - off >> PAGE_SHIFT); p_off = offset_in_page(off); p_cnt = PAGE_SIZE - p_off; p_cnt = min(p_cnt, length); local_irq_save(flags); - buf = kmap_atomic(pg) + p_off; + buf = sg_map(>req->sg, +off - host->req->sg.offset, +SG_KMAP_ATOMIC | SG_MAP_MUST_NOT_FAIL); } else { buf = host->req->data + host->block_pos; p_cnt = host->req->data_len - host->block_pos; @@ -341,7 +340,9 @@ static int jmb38x_ms_transfer_data(struct jmb38x_ms_host *host) : jmb38x_ms_read_reg_data(host, buf, p_cnt); if (host->req->long_data) { - kunmap_atomic(buf - p_off); + sg_unmap(>req->sg, buf, +off - host->req->sg.offset, +SG_KMAP_ATOMIC); local_irq_restore(flags); } diff --git a/drivers/memstick/host/tifm_ms.c b/drivers/memstick/host/tifm_ms.c index 7bafa72..304985d 100644 --- a/drivers/memstick/host/tifm_ms.c +++ b/drivers/memstick/host/tifm_ms.c @@ -186,7 +186,6 @@ static unsigned int tifm_ms_transfer_data(struct tifm_ms *host) unsigned int off; unsigned int t_size, p_cnt; unsigned char *buf; - struct page *pg; unsigned long flags = 0; if (host->req->long_data) { @@ -203,14 +202,14 @@ static unsigned int tifm_ms_transfer_data(struct tifm_ms *host) unsigned int uninitialized_var(p_off); if (host->req->long_data) { - pg = nth_page(sg_page(>req->sg), - off >> PAGE_SHIFT); p_off = offset_in_page(off); p_cnt = PAGE_SIZE - p_off; p_cnt = min(p_cnt, length); local_irq_save(flags); - buf = kmap_atomic(pg) + p_off; + buf = sg_map(>req->sg, +off - host->req->sg.offset, +SG_KMAP_ATOMIC | SG_MAP_MUST_NOT_FAIL); } else { buf = host->req->data + host->block_pos; p_cnt = host->req->data_len - host->block_pos; @@ -221,7 +220,9 @@ static unsigned int tifm_ms_transfer_data(struct tifm_ms *host) : tifm_ms_read_data(host, buf, p_cnt); if (host->req->long_data) { - kunmap_atomic(buf - p_off); + sg_unmap(>req->sg, buf, +off - host->req->sg.offset, +SG_KMAP_ATOMIC | SG_MAP_MUST_NOT_FAIL); local_irq_restore(flags); } -- 2.1.4
[PATCH v2 17/21] mmc: spi: Make use of the new sg_map helper function
We use the sg_map helper but it's slightly more complicated as we only check for the error when the mapping actually gets used. Such that if the mapping failed but wasn't needed then no error occurs. Signed-off-by: Logan GunthorpeCc: Ulf Hansson --- drivers/mmc/host/mmc_spi.c | 26 +++--- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c index 476e53d..d614f36 100644 --- a/drivers/mmc/host/mmc_spi.c +++ b/drivers/mmc/host/mmc_spi.c @@ -676,9 +676,15 @@ mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t, struct scratch *scratch = host->data; u32 pattern; - if (host->mmc->use_spi_crc) + if (host->mmc->use_spi_crc) { + if (IS_ERR(t->tx_buf)) + return PTR_ERR(t->tx_buf); + scratch->crc_val = cpu_to_be16( crc_itu_t(0, t->tx_buf, t->len)); + t->tx_buf += t->len; + } + if (host->dma_dev) dma_sync_single_for_device(host->dma_dev, host->data_dma, sizeof(*scratch), @@ -743,7 +749,6 @@ mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t, return status; } - t->tx_buf += t->len; if (host->dma_dev) t->tx_dma += t->len; @@ -809,6 +814,11 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t, } leftover = status << 1; + if (bitshift || host->mmc->use_spi_crc) { + if (IS_ERR(t->rx_buf)) + return PTR_ERR(t->rx_buf); + } + if (host->dma_dev) { dma_sync_single_for_device(host->dma_dev, host->data_dma, sizeof(*scratch), @@ -860,9 +870,10 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t, scratch->crc_val, crc, t->len); return -EILSEQ; } + + t->rx_buf += t->len; } - t->rx_buf += t->len; if (host->dma_dev) t->rx_dma += t->len; @@ -933,11 +944,11 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd, } /* allow pio too; we don't allow highmem */ - kmap_addr = kmap(sg_page(sg)); + kmap_addr = sg_map(sg, 0, SG_KMAP); if (direction == DMA_TO_DEVICE) - t->tx_buf = kmap_addr + sg->offset; + t->tx_buf = kmap_addr; else - t->rx_buf = kmap_addr + sg->offset; + t->rx_buf = kmap_addr; /* transfer each block, and update request status */ while (length) { @@ -967,7 +978,8 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd, /* discard mappings */ if (direction == DMA_FROM_DEVICE) flush_kernel_dcache_page(sg_page(sg)); - kunmap(sg_page(sg)); + if (!IS_ERR(kmap_addr)) + sg_unmap(sg, kmap_addr, 0, SG_KMAP); if (dma_dev) dma_unmap_page(dma_dev, dma_addr, PAGE_SIZE, dir); -- 2.1.4
[PATCH v2 09/21] staging: unisys: visorbus: Make use of the new sg_map helper function
Straightforward conversion to the new function. Signed-off-by: Logan GunthorpeAcked-by: David Kershner --- drivers/staging/unisys/visorhba/visorhba_main.c | 12 +++- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/staging/unisys/visorhba/visorhba_main.c b/drivers/staging/unisys/visorhba/visorhba_main.c index d372115..c77426c 100644 --- a/drivers/staging/unisys/visorhba/visorhba_main.c +++ b/drivers/staging/unisys/visorhba/visorhba_main.c @@ -843,7 +843,6 @@ do_scsi_nolinuxstat(struct uiscmdrsp *cmdrsp, struct scsi_cmnd *scsicmd) struct scatterlist *sg; unsigned int i; char *this_page; - char *this_page_orig; int bufind = 0; struct visordisk_info *vdisk; struct visorhba_devdata *devdata; @@ -870,11 +869,14 @@ do_scsi_nolinuxstat(struct uiscmdrsp *cmdrsp, struct scsi_cmnd *scsicmd) sg = scsi_sglist(scsicmd); for (i = 0; i < scsi_sg_count(scsicmd); i++) { - this_page_orig = kmap_atomic(sg_page(sg + i)); - this_page = (void *)((unsigned long)this_page_orig | -sg[i].offset); + this_page = sg_map(sg + i, 0, SG_KMAP_ATOMIC); + if (IS_ERR(this_page)) { + scsicmd->result = DID_ERROR << 16; + return; + } + memcpy(this_page, buf + bufind, sg[i].length); - kunmap_atomic(this_page_orig); + sg_unmap(sg + i, this_page, 0, SG_KMAP_ATOMIC); } } else { devdata = (struct visorhba_devdata *)scsidev->host->hostdata; -- 2.1.4
[PATCH v2 06/21] crypto: hifn_795x: Make use of the new sg_map helper function
Conversion of a couple kmap_atomic instances to the sg_map helper function. However, it looks like there was a bug in the original code: the source scatter lists offset (t->offset) was passed to ablkcipher_get which added it to the destination address. This doesn't make a lot of sense, but t->offset is likely always zero anyway. So, this patch cleans that brokeness up. Also, a change to the error path: if ablkcipher_get failed, everything seemed to proceed as if it hadn't. Setting 'error' should hopefully clear that up. Signed-off-by: Logan GunthorpeCc: Herbert Xu Cc: "David S. Miller" --- drivers/crypto/hifn_795x.c | 32 +--- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c index e09d405..34b1870 100644 --- a/drivers/crypto/hifn_795x.c +++ b/drivers/crypto/hifn_795x.c @@ -1619,7 +1619,7 @@ static int hifn_start_device(struct hifn_device *dev) return 0; } -static int ablkcipher_get(void *saddr, unsigned int *srestp, unsigned int offset, +static int ablkcipher_get(void *saddr, unsigned int *srestp, struct scatterlist *dst, unsigned int size, unsigned int *nbytesp) { unsigned int srest = *srestp, nbytes = *nbytesp, copy; @@ -1632,15 +1632,17 @@ static int ablkcipher_get(void *saddr, unsigned int *srestp, unsigned int offset while (size) { copy = min3(srest, dst->length, size); - daddr = kmap_atomic(sg_page(dst)); - memcpy(daddr + dst->offset + offset, saddr, copy); - kunmap_atomic(daddr); + daddr = sg_map(dst, 0, SG_KMAP_ATOMIC); + if (IS_ERR(daddr)) + return PTR_ERR(daddr); + + memcpy(daddr, saddr, copy); + sg_unmap(dst, daddr, 0, SG_KMAP_ATOMIC); nbytes -= copy; size -= copy; srest -= copy; saddr += copy; - offset = 0; pr_debug("%s: copy: %u, size: %u, srest: %u, nbytes: %u.\n", __func__, copy, size, srest, nbytes); @@ -1671,11 +1673,12 @@ static inline void hifn_complete_sa(struct hifn_device *dev, int i) static void hifn_process_ready(struct ablkcipher_request *req, int error) { + int err; struct hifn_request_context *rctx = ablkcipher_request_ctx(req); if (rctx->walk.flags & ASYNC_FLAGS_MISALIGNED) { unsigned int nbytes = req->nbytes; - int idx = 0, err; + int idx = 0; struct scatterlist *dst, *t; void *saddr; @@ -1695,17 +1698,24 @@ static void hifn_process_ready(struct ablkcipher_request *req, int error) continue; } - saddr = kmap_atomic(sg_page(t)); + saddr = sg_map(t, 0, SG_KMAP_ATOMIC); + if (IS_ERR(saddr)) { + if (!error) + error = PTR_ERR(saddr); + break; + } + + err = ablkcipher_get(saddr, >length, +dst, nbytes, ); + sg_unmap(t, saddr, 0, SG_KMAP_ATOMIC); - err = ablkcipher_get(saddr, >length, t->offset, - dst, nbytes, ); if (err < 0) { - kunmap_atomic(saddr); + if (!error) + error = err; break; } idx += err; - kunmap_atomic(saddr); } hifn_cipher_walk_exit(>walk); -- 2.1.4
[PATCH v2 10/21] RDS: Make use of the new sg_map helper function
Straightforward conversion except there's no error path, so we make use of SG_MAP_MUST_NOT_FAIL which may BUG_ON in certain cases in the future. Signed-off-by: Logan GunthorpeCc: Santosh Shilimkar Cc: "David S. Miller" --- net/rds/ib_recv.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c index e10624a..c665689 100644 --- a/net/rds/ib_recv.c +++ b/net/rds/ib_recv.c @@ -800,10 +800,10 @@ static void rds_ib_cong_recv(struct rds_connection *conn, to_copy = min(RDS_FRAG_SIZE - frag_off, PAGE_SIZE - map_off); BUG_ON(to_copy & 7); /* Must be 64bit aligned. */ + addr = sg_map(>f_sg, 0, + SG_KMAP_ATOMIC | SG_MAP_MUST_NOT_FAIL); - addr = kmap_atomic(sg_page(>f_sg)); - - src = addr + frag->f_sg.offset + frag_off; + src = addr + frag_off; dst = (void *)map->m_page_addrs[map_page] + map_off; for (k = 0; k < to_copy; k += 8) { /* Record ports that became uncongested, ie @@ -811,7 +811,7 @@ static void rds_ib_cong_recv(struct rds_connection *conn, uncongested |= ~(*src) & *dst; *dst++ = *src++; } - kunmap_atomic(addr); + sg_unmap(>f_sg, addr, 0, SG_KMAP_ATOMIC); copied += to_copy; -- 2.1.4
[PATCH v2 12/21] scsi: hisi_sas, mvsas, gdth: Make use of the new sg_map helper function
Very straightforward conversion of three scsi drivers. Signed-off-by: Logan GunthorpeCc: Achim Leubner Cc: John Garry --- drivers/scsi/gdth.c| 9 +++-- drivers/scsi/hisi_sas/hisi_sas_v1_hw.c | 14 +- drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 13 + drivers/scsi/mvsas/mv_sas.c| 10 +- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c index d020a13..c70248a2 100644 --- a/drivers/scsi/gdth.c +++ b/drivers/scsi/gdth.c @@ -2301,10 +2301,15 @@ static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp, return; } local_irq_save(flags); -address = kmap_atomic(sg_page(sl)) + sl->offset; +address = sg_map(sl, 0, SG_KMAP_ATOMIC); +if (IS_ERR(address)) { +scp->result = DID_ERROR << 16; +return; + } + memcpy(address, buffer, cpnow); flush_dcache_page(sg_page(sl)); -kunmap_atomic(address); +sg_unmap(sl, address, 0, SG_KMAP_ATOMIC); local_irq_restore(flags); if (cpsum == cpcount) break; diff --git a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c index fc1c1b2..b3953e3 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c @@ -1381,18 +1381,22 @@ static int slot_complete_v1_hw(struct hisi_hba *hisi_hba, void *to; struct scatterlist *sg_resp = >smp_task.smp_resp; - ts->stat = SAM_STAT_GOOD; - to = kmap_atomic(sg_page(sg_resp)); + to = sg_map(sg_resp, 0, SG_KMAP_ATOMIC); + if (IS_ERR(to)) { + dev_err(dev, "slot complete: error mapping memory"); + ts->stat = SAS_SG_ERR; + break; + } + ts->stat = SAM_STAT_GOOD; dma_unmap_sg(dev, >smp_task.smp_resp, 1, DMA_FROM_DEVICE); dma_unmap_sg(dev, >smp_task.smp_req, 1, DMA_TO_DEVICE); - memcpy(to + sg_resp->offset, - slot->status_buffer + + memcpy(to, slot->status_buffer + sizeof(struct hisi_sas_err_record), sg_dma_len(sg_resp)); - kunmap_atomic(to); + sg_unmap(sg_resp, to, 0, SG_KMAP_ATOMIC); break; } case SAS_PROTOCOL_SATA: diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c index e241921..3e674a4 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c @@ -2307,18 +2307,23 @@ slot_complete_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_slot *slot) struct scatterlist *sg_resp = >smp_task.smp_resp; void *to; + to = sg_map(sg_resp, 0, SG_KMAP_ATOMIC); + if (IS_ERR(to)) { + dev_err(dev, "slot complete: error mapping memory"); + ts->stat = SAS_SG_ERR; + break; + } + ts->stat = SAM_STAT_GOOD; - to = kmap_atomic(sg_page(sg_resp)); dma_unmap_sg(dev, >smp_task.smp_resp, 1, DMA_FROM_DEVICE); dma_unmap_sg(dev, >smp_task.smp_req, 1, DMA_TO_DEVICE); - memcpy(to + sg_resp->offset, - slot->status_buffer + + memcpy(to, slot->status_buffer + sizeof(struct hisi_sas_err_record), sg_dma_len(sg_resp)); - kunmap_atomic(to); + sg_unmap(sg_resp, to, 0, SG_KMAP_ATOMIC); break; } case SAS_PROTOCOL_SATA: diff --git a/drivers/scsi/mvsas/mv_sas.c b/drivers/scsi/mvsas/mv_sas.c index c7cc803..a72e0ce 100644 --- a/drivers/scsi/mvsas/mv_sas.c +++ b/drivers/scsi/mvsas/mv_sas.c @@ -1798,11 +1798,11 @@ int mvs_slot_complete(struct mvs_info *mvi, u32 rx_desc, u32 flags) case SAS_PROTOCOL_SMP: { struct scatterlist *sg_resp = >smp_task.smp_resp; tstat->stat = SAM_STAT_GOOD; - to = kmap_atomic(sg_page(sg_resp)); - memcpy(to + sg_resp->offset, - slot->response + sizeof(struct mvs_err_info), - sg_dma_len(sg_resp)); - kunmap_atomic(to); + to = sg_map(sg_resp, 0, SG_KMAP_ATOMIC); + memcpy(to, + slot->response + sizeof(struct mvs_err_info), +
[PATCH v2 13/21] scsi: arcmsr, ips, megaraid: Make use of the new sg_map helper function
Very straightforward conversion of three scsi drivers Signed-off-by: Logan GunthorpeCc: Adaptec OEM Raid Solutions Cc: Kashyap Desai Cc: Sumit Saxena Cc: Shivasharan S --- drivers/scsi/arcmsr/arcmsr_hba.c | 16 drivers/scsi/ips.c | 8 drivers/scsi/megaraid.c | 9 +++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c index af032c4..8c2de17 100644 --- a/drivers/scsi/arcmsr/arcmsr_hba.c +++ b/drivers/scsi/arcmsr/arcmsr_hba.c @@ -2306,7 +2306,10 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, use_sg = scsi_sg_count(cmd); sg = scsi_sglist(cmd); - buffer = kmap_atomic(sg_page(sg)) + sg->offset; + buffer = sg_map(sg, 0, SG_KMAP_ATOMIC); + if (IS_ERR(buffer)) + return ARCMSR_MESSAGE_FAIL; + if (use_sg > 1) { retvalue = ARCMSR_MESSAGE_FAIL; goto message_out; @@ -2539,7 +2542,7 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, message_out: if (use_sg) { struct scatterlist *sg = scsi_sglist(cmd); - kunmap_atomic(buffer - sg->offset); + sg_unmap(sg, buffer, 0, SG_KMAP_ATOMIC); } return retvalue; } @@ -2590,11 +2593,16 @@ static void arcmsr_handle_virtual_command(struct AdapterControlBlock *acb, strncpy([32], "R001", 4); /* Product Revision */ sg = scsi_sglist(cmd); - buffer = kmap_atomic(sg_page(sg)) + sg->offset; + buffer = sg_map(sg, 0, SG_KMAP_ATOMIC); + if (IS_ERR(buffer)) { + cmd->result = (DID_ERROR << 16); + cmd->scsi_done(cmd); + return; + } memcpy(buffer, inqdata, sizeof(inqdata)); sg = scsi_sglist(cmd); - kunmap_atomic(buffer - sg->offset); + sg_unmap(sg, buffer, 0, SG_KMAP_ATOMIC); cmd->scsi_done(cmd); } diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c index 3419e1b..6e91729 100644 --- a/drivers/scsi/ips.c +++ b/drivers/scsi/ips.c @@ -1506,14 +1506,14 @@ static int ips_is_passthru(struct scsi_cmnd *SC) /* kmap_atomic() ensures addressability of the user buffer.*/ /* local_irq_save() protects the KM_IRQ0 address slot. */ local_irq_save(flags); -buffer = kmap_atomic(sg_page(sg)) + sg->offset; -if (buffer && buffer[0] == 'C' && buffer[1] == 'O' && +buffer = sg_map(sg, 0, SG_KMAP_ATOMIC); +if (!IS_ERR(buffer) && buffer[0] == 'C' && buffer[1] == 'O' && buffer[2] == 'P' && buffer[3] == 'P') { -kunmap_atomic(buffer - sg->offset); +sg_unmap(sg, buffer, 0, SG_KMAP_ATOMIC); local_irq_restore(flags); return 1; } -kunmap_atomic(buffer - sg->offset); +sg_unmap(sg, buffer, 0, SG_KMAP_ATOMIC); local_irq_restore(flags); } return 0; diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c index 3c63c29..f8aee59 100644 --- a/drivers/scsi/megaraid.c +++ b/drivers/scsi/megaraid.c @@ -663,10 +663,15 @@ mega_build_cmd(adapter_t *adapter, Scsi_Cmnd *cmd, int *busy) struct scatterlist *sg; sg = scsi_sglist(cmd); - buf = kmap_atomic(sg_page(sg)) + sg->offset; + buf = sg_map(sg, 0, SG_KMAP_ATOMIC); + if (IS_ERR(buf)) { +cmd->result = (DID_ERROR << 16); + cmd->scsi_done(cmd); + return NULL; + } memset(buf, 0, cmd->cmnd[4]); - kunmap_atomic(buf - sg->offset); + sg_unmap(sg, buf, 0, SG_KMAP_ATOMIC); cmd->result = (DID_OK << 16); cmd->scsi_done(cmd); -- 2.1.4
[PATCH v2 20/21] mmc: tifm_sd: Make use of the new sg_map helper function
This conversion is a bit complicated. We modiy the read_fifo, write_fifo and copy_page functions to take a scatterlist instead of a page. Thus we can use sg_map instead of kmap_atomic. There's a bit of accounting that needed to be done for the offset for this to work. (Seeing sg_map takes care of the offset but it's already added and used earlier in the code.) There's also no error path, so we use SG_MAP_MUST_NOT_FAIL which may BUG_ON in certain cases in the future. Signed-off-by: Logan GunthorpeCc: Alex Dubov Cc: Ulf Hansson --- drivers/mmc/host/tifm_sd.c | 50 +++--- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/drivers/mmc/host/tifm_sd.c b/drivers/mmc/host/tifm_sd.c index 93c4b40..e64345a 100644 --- a/drivers/mmc/host/tifm_sd.c +++ b/drivers/mmc/host/tifm_sd.c @@ -111,14 +111,16 @@ struct tifm_sd { }; /* for some reason, host won't respond correctly to readw/writew */ -static void tifm_sd_read_fifo(struct tifm_sd *host, struct page *pg, +static void tifm_sd_read_fifo(struct tifm_sd *host, struct scatterlist *sg, unsigned int off, unsigned int cnt) { struct tifm_dev *sock = host->dev; unsigned char *buf; unsigned int pos = 0, val; - buf = kmap_atomic(pg) + off; + buf = sg_map(sg, off - sg->offset, +SG_KMAP_ATOMIC | SG_MAP_MUST_NOT_FAIL); + if (host->cmd_flags & DATA_CARRY) { buf[pos++] = host->bounce_buf_data[0]; host->cmd_flags &= ~DATA_CARRY; @@ -134,17 +136,19 @@ static void tifm_sd_read_fifo(struct tifm_sd *host, struct page *pg, } buf[pos++] = (val >> 8) & 0xff; } - kunmap_atomic(buf - off); + sg_unmap(sg, buf, off - sg->offset, SG_KMAP_ATOMIC); } -static void tifm_sd_write_fifo(struct tifm_sd *host, struct page *pg, +static void tifm_sd_write_fifo(struct tifm_sd *host, struct scatterlist *sg, unsigned int off, unsigned int cnt) { struct tifm_dev *sock = host->dev; unsigned char *buf; unsigned int pos = 0, val; - buf = kmap_atomic(pg) + off; + buf = sg_map(sg, off - sg->offset, +SG_KMAP_ATOMIC | SG_MAP_MUST_NOT_FAIL); + if (host->cmd_flags & DATA_CARRY) { val = host->bounce_buf_data[0] | ((buf[pos++] << 8) & 0xff00); writel(val, sock->addr + SOCK_MMCSD_DATA); @@ -161,7 +165,7 @@ static void tifm_sd_write_fifo(struct tifm_sd *host, struct page *pg, val |= (buf[pos++] << 8) & 0xff00; writel(val, sock->addr + SOCK_MMCSD_DATA); } - kunmap_atomic(buf - off); + sg_unmap(sg, buf, off - sg->offset, SG_KMAP_ATOMIC); } static void tifm_sd_transfer_data(struct tifm_sd *host) @@ -170,7 +174,6 @@ static void tifm_sd_transfer_data(struct tifm_sd *host) struct scatterlist *sg = r_data->sg; unsigned int off, cnt, t_size = TIFM_MMCSD_FIFO_SIZE * 2; unsigned int p_off, p_cnt; - struct page *pg; if (host->sg_pos == host->sg_len) return; @@ -192,33 +195,39 @@ static void tifm_sd_transfer_data(struct tifm_sd *host) } off = sg[host->sg_pos].offset + host->block_pos; - pg = nth_page(sg_page([host->sg_pos]), off >> PAGE_SHIFT); p_off = offset_in_page(off); p_cnt = PAGE_SIZE - p_off; p_cnt = min(p_cnt, cnt); p_cnt = min(p_cnt, t_size); if (r_data->flags & MMC_DATA_READ) - tifm_sd_read_fifo(host, pg, p_off, p_cnt); + tifm_sd_read_fifo(host, [host->sg_pos], p_off, + p_cnt); else if (r_data->flags & MMC_DATA_WRITE) - tifm_sd_write_fifo(host, pg, p_off, p_cnt); + tifm_sd_write_fifo(host, [host->sg_pos], p_off, + p_cnt); t_size -= p_cnt; host->block_pos += p_cnt; } } -static void tifm_sd_copy_page(struct page *dst, unsigned int dst_off, - struct page *src, unsigned int src_off, +static void tifm_sd_copy_page(struct scatterlist *dst, unsigned int dst_off, + struct scatterlist *src, unsigned int src_off, unsigned int count) { - unsigned char *src_buf = kmap_atomic(src) + src_off; - unsigned char *dst_buf = kmap_atomic(dst) + dst_off; + unsigned char *src_buf, *dst_buf; + + src_off -= src->offset; + dst_off -= dst->offset; + + src_buf = sg_map(src, src_off, SG_KMAP_ATOMIC | SG_MAP_MUST_NOT_FAIL); + dst_buf = sg_map(dst, dst_off, SG_KMAP_ATOMIC | SG_MAP_MUST_NOT_FAIL); memcpy(dst_buf, src_buf,
[PATCH v2 15/21] xen-blkfront: Make use of the new sg_map helper function
Straightforward conversion to the new helper, except due to the lack of error path, we have to use SG_MAP_MUST_NOT_FAIL which may BUG_ON in certain cases in the future. Signed-off-by: Logan GunthorpeCc: Boris Ostrovsky Cc: Juergen Gross Cc: Konrad Rzeszutek Wilk Cc: "Roger Pau Monné" --- drivers/block/xen-blkfront.c | 20 +++- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 3945963..ed62175 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -816,8 +816,9 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri BUG_ON(sg->offset + sg->length > PAGE_SIZE); if (setup.need_copy) { - setup.bvec_off = sg->offset; - setup.bvec_data = kmap_atomic(sg_page(sg)); + setup.bvec_off = 0; + setup.bvec_data = sg_map(sg, 0, SG_KMAP_ATOMIC | +SG_MAP_MUST_NOT_FAIL); } gnttab_foreach_grant_in_range(sg_page(sg), @@ -827,7 +828,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri ); if (setup.need_copy) - kunmap_atomic(setup.bvec_data); + sg_unmap(sg, setup.bvec_data, 0, SG_KMAP_ATOMIC); } if (setup.segments) kunmap_atomic(setup.segments); @@ -1053,7 +1054,7 @@ static int xen_translate_vdev(int vdevice, int *minor, unsigned int *offset) case XEN_SCSI_DISK5_MAJOR: case XEN_SCSI_DISK6_MAJOR: case XEN_SCSI_DISK7_MAJOR: - *offset = (*minor / PARTS_PER_DISK) + + *offset = (*minor / PARTS_PER_DISK) + ((major - XEN_SCSI_DISK1_MAJOR + 1) * 16) + EMULATED_SD_DISK_NAME_OFFSET; *minor = *minor + @@ -1068,7 +1069,7 @@ static int xen_translate_vdev(int vdevice, int *minor, unsigned int *offset) case XEN_SCSI_DISK13_MAJOR: case XEN_SCSI_DISK14_MAJOR: case XEN_SCSI_DISK15_MAJOR: - *offset = (*minor / PARTS_PER_DISK) + + *offset = (*minor / PARTS_PER_DISK) + ((major - XEN_SCSI_DISK8_MAJOR + 8) * 16) + EMULATED_SD_DISK_NAME_OFFSET; *minor = *minor + @@ -1119,7 +1120,7 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, if (!VDEV_IS_EXTENDED(info->vdevice)) { err = xen_translate_vdev(info->vdevice, , ); if (err) - return err; + return err; nr_parts = PARTS_PER_DISK; } else { minor = BLKIF_MINOR_EXT(info->vdevice); @@ -1483,8 +1484,9 @@ static bool blkif_completion(unsigned long *id, for_each_sg(s->sg, sg, num_sg, i) { BUG_ON(sg->offset + sg->length > PAGE_SIZE); - data.bvec_offset = sg->offset; - data.bvec_data = kmap_atomic(sg_page(sg)); + data.bvec_offset = 0; + data.bvec_data = sg_map(sg, 0, SG_KMAP_ATOMIC | + SG_MAP_MUST_NOT_FAIL); gnttab_foreach_grant_in_range(sg_page(sg), sg->offset, @@ -1492,7 +1494,7 @@ static bool blkif_completion(unsigned long *id, blkif_copy_from_grant, ); - kunmap_atomic(data.bvec_data); + sg_unmap(sg, data.bvec_data, 0, SG_KMAP_ATOMIC); } } /* Add the persistent grant into the list of free grants */ -- 2.1.4
[PATCH v2 19/21] mmc: sdricoh_cs: Make use of the new sg_map helper function
This is a straightforward conversion to the new function. Signed-off-by: Logan GunthorpeCc: Sascha Sommer Cc: Ulf Hansson --- drivers/mmc/host/sdricoh_cs.c | 14 +- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c index 5ff26ab..03225c3 100644 --- a/drivers/mmc/host/sdricoh_cs.c +++ b/drivers/mmc/host/sdricoh_cs.c @@ -319,16 +319,20 @@ static void sdricoh_request(struct mmc_host *mmc, struct mmc_request *mrq) for (i = 0; i < data->blocks; i++) { size_t len = data->blksz; u8 *buf; - struct page *page; int result; - page = sg_page(data->sg); - buf = kmap(page) + data->sg->offset + (len * i); + buf = sg_map(data->sg, (len * i), SG_KMAP); + if (IS_ERR(buf)) { + cmd->error = PTR_ERR(buf); + break; + } + result = sdricoh_blockio(host, data->flags & MMC_DATA_READ, buf, len); - kunmap(page); - flush_dcache_page(page); + sg_unmap(data->sg, buf, (len * i), SG_KMAP); + + flush_dcache_page(sg_page(data->sg)); if (result) { dev_err(dev, "sdricoh_request: cmd %i " "block transfer failed\n", cmd->opcode); -- 2.1.4
[PATCH v2 01/21] scatterlist: Introduce sg_map helper functions
This patch introduces functions which kmap the pages inside an sgl. These functions replace a common pattern of kmap(sg_page(sg)) that is used in more than 50 places within the kernel. The motivation for this work is to eventually safely support sgls that contain io memory. In order for that to work, any access to the contents of an iomem SGL will need to be done with iomemcpy or hit some warning. (The exact details of how this will work have yet to be worked out.) Having all the kmaps in one place is just a first step in that direction. Additionally, seeing this helps cut down the users of sg_page, it should make any effort to go to struct-page-less DMAs a little easier (should that idea ever swing back into favour again). A flags option is added to select between a regular or atomic mapping so these functions can replace kmap(sg_page or kmap_atomic(sg_page. Future work may expand this to have flags for using page_address or vmap. We include a flag to require the function not to fail to support legacy code that has no easy error path. Much further in the future, there may be a flag to allocate memory and copy the data from/to iomem. We also add the semantic that sg_map can fail to create a mapping, despite the fact that the current code this is replacing is assumed to never fail and the current version of these functions cannot fail. This is to support iomem which may either have to fail to create the mapping or allocate memory as a bounce buffer which itself can fail. Also, in terms of cleanup, a few of the existing kmap(sg_page) users play things a bit loose in terms of whether they apply sg->offset so using these helper functions should help avoid such issues. Signed-off-by: Logan Gunthorpe--- include/linux/scatterlist.h | 85 + 1 file changed, 85 insertions(+) diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index cb3c8fe..fad170b 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -5,6 +5,7 @@ #include #include #include +#include #include struct scatterlist { @@ -126,6 +127,90 @@ static inline struct page *sg_page(struct scatterlist *sg) return (struct page *)((sg)->page_link & ~0x3); } +#define SG_KMAP (1 << 0) /* create a mapping with kmap */ +#define SG_KMAP_ATOMIC (1 << 1) /* create a mapping with kmap_atomic */ +#define SG_MAP_MUST_NOT_FAIL (1 << 2) /* indicate sg_map should not fail */ + +/** + * sg_map - kmap a page inside an sgl + * @sg:SG entry + * @offset:Offset into entry + * @flags: Flags for creating the mapping + * + * Description: + * Use this function to map a page in the scatterlist at the specified + * offset. sg->offset is already added for you. Note: the semantics of + * this function are that it may fail. Thus, its output should be checked + * with IS_ERR and PTR_ERR. Otherwise, a pointer to the specified offset + * in the mapped page is returned. + * + * Flags can be any of: + * * SG_KMAP - Use kmap to create the mapping + * * SG_KMAP_ATOMIC- Use kmap_atomic to map the page atommically. + * Thus, the rules of that function apply: the + * cpu may not sleep until it is unmaped. + * * SG_MAP_MUST_NOT_FAIL - Indicate that sg_map must not fail. + * If it does, it will issue a BUG_ON instead. + * This is intended for legacy code only, it + * is not to be used in new code. + * + * Also, consider carefully whether this function is appropriate. It is + * largely not recommended for new code and if the sgl came from another + * subsystem and you don't know what kind of memory might be in the list + * then you definitely should not call it. Non-mappable memory may be in + * the sgl and thus this function may fail unexpectedly. Consider using + * sg_copy_to_buffer instead. + **/ +static inline void *sg_map(struct scatterlist *sg, size_t offset, int flags) +{ + struct page *pg; + unsigned int pg_off; + void *ret; + + offset += sg->offset; + pg = nth_page(sg_page(sg), offset >> PAGE_SHIFT); + pg_off = offset_in_page(offset); + + if (flags & SG_KMAP_ATOMIC) + ret = kmap_atomic(pg) + pg_off; + else if (flags & SG_KMAP) + ret = kmap(pg) + pg_off; + else + ret = ERR_PTR(-EINVAL); + + /* +* In theory, this can't happen yet. Once we start adding +* unmapable memory, it also shouldn't happen unless developers +* start putting unmappable struct pages in sgls and passing +* it to code that doesn't support it. +*/ + BUG_ON(flags & SG_MAP_MUST_NOT_FAIL && IS_ERR(ret)); + + return ret; +} + +/** + * sg_unmap - unmap a page that was mapped with
[PATCH v2 05/21] drm/i915: Make use of the new sg_map helper function
This is a single straightforward conversion from kmap to sg_map. We also create the i915_gem_object_unmap function to common up the unmap code. Signed-off-by: Logan GunthorpeAcked-by: Daniel Vetter --- drivers/gpu/drm/i915/i915_gem.c | 27 --- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 07e9b27..2c33000 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2202,6 +2202,15 @@ static void __i915_gem_object_reset_page_iter(struct drm_i915_gem_object *obj) radix_tree_delete(>mm.get_page.radix, iter.index); } +static void i915_gem_object_unmap(const struct drm_i915_gem_object *obj, + void *ptr) +{ + if (is_vmalloc_addr(ptr)) + vunmap(ptr); + else + sg_unmap(obj->mm.pages->sgl, ptr, 0, SG_KMAP); +} + void __i915_gem_object_put_pages(struct drm_i915_gem_object *obj, enum i915_mm_subclass subclass) { @@ -2229,10 +2238,7 @@ void __i915_gem_object_put_pages(struct drm_i915_gem_object *obj, void *ptr; ptr = ptr_mask_bits(obj->mm.mapping); - if (is_vmalloc_addr(ptr)) - vunmap(ptr); - else - kunmap(kmap_to_page(ptr)); + i915_gem_object_unmap(obj, ptr); obj->mm.mapping = NULL; } @@ -2499,8 +2505,11 @@ static void *i915_gem_object_map(const struct drm_i915_gem_object *obj, void *addr; /* A single page can always be kmapped */ - if (n_pages == 1 && type == I915_MAP_WB) - return kmap(sg_page(sgt->sgl)); + if (n_pages == 1 && type == I915_MAP_WB) { + addr = sg_map(sgt->sgl, 0, SG_KMAP); + if (IS_ERR(addr)) + return NULL; + } if (n_pages > ARRAY_SIZE(stack_pages)) { /* Too big for stack -- allocate temporary array instead */ @@ -2567,11 +2576,7 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj, goto err_unpin; } - if (is_vmalloc_addr(ptr)) - vunmap(ptr); - else - kunmap(kmap_to_page(ptr)); - + i915_gem_object_unmap(obj, ptr); ptr = obj->mm.mapping = NULL; } -- 2.1.4
[PATCH v2 08/21] dm-crypt: Make use of the new sg_map helper in 4 call sites
Very straightforward conversion to the new function in all four spots. Signed-off-by: Logan GunthorpeCc: Alasdair Kergon Cc: Mike Snitzer --- drivers/md/dm-crypt.c | 39 ++- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 8dbecf1..841f1fc 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -635,9 +635,12 @@ static int crypt_iv_lmk_gen(struct crypt_config *cc, u8 *iv, if (bio_data_dir(dmreq->ctx->bio_in) == WRITE) { sg = crypt_get_sg_data(cc, dmreq->sg_in); - src = kmap_atomic(sg_page(sg)); - r = crypt_iv_lmk_one(cc, iv, dmreq, src + sg->offset); - kunmap_atomic(src); + src = sg_map(sg, 0, SG_KMAP_ATOMIC); + if (IS_ERR(src)) + return PTR_ERR(src); + + r = crypt_iv_lmk_one(cc, iv, dmreq, src); + sg_unmap(sg, src, 0, SG_KMAP_ATOMIC); } else memset(iv, 0, cc->iv_size); @@ -655,14 +658,18 @@ static int crypt_iv_lmk_post(struct crypt_config *cc, u8 *iv, return 0; sg = crypt_get_sg_data(cc, dmreq->sg_out); - dst = kmap_atomic(sg_page(sg)); - r = crypt_iv_lmk_one(cc, iv, dmreq, dst + sg->offset); + dst = sg_map(sg, 0, SG_KMAP_ATOMIC); + if (IS_ERR(dst)) + return PTR_ERR(dst); + + r = crypt_iv_lmk_one(cc, iv, dmreq, dst); /* Tweak the first block of plaintext sector */ if (!r) - crypto_xor(dst + sg->offset, iv, cc->iv_size); + crypto_xor(dst, iv, cc->iv_size); + + sg_unmap(sg, dst, 0, SG_KMAP_ATOMIC); - kunmap_atomic(dst); return r; } @@ -786,9 +793,12 @@ static int crypt_iv_tcw_gen(struct crypt_config *cc, u8 *iv, /* Remove whitening from ciphertext */ if (bio_data_dir(dmreq->ctx->bio_in) != WRITE) { sg = crypt_get_sg_data(cc, dmreq->sg_in); - src = kmap_atomic(sg_page(sg)); - r = crypt_iv_tcw_whitening(cc, dmreq, src + sg->offset); - kunmap_atomic(src); + src = sg_map(sg, 0, SG_KMAP_ATOMIC); + if (IS_ERR(src)) + return PTR_ERR(src); + + r = crypt_iv_tcw_whitening(cc, dmreq, src); + sg_unmap(sg, src, 0, SG_KMAP_ATOMIC); } /* Calculate IV */ @@ -812,9 +822,12 @@ static int crypt_iv_tcw_post(struct crypt_config *cc, u8 *iv, /* Apply whitening on ciphertext */ sg = crypt_get_sg_data(cc, dmreq->sg_out); - dst = kmap_atomic(sg_page(sg)); - r = crypt_iv_tcw_whitening(cc, dmreq, dst + sg->offset); - kunmap_atomic(dst); + dst = sg_map(sg, 0, SG_KMAP_ATOMIC); + if (IS_ERR(dst)) + return PTR_ERR(dst); + + r = crypt_iv_tcw_whitening(cc, dmreq, dst); + sg_unmap(sg, dst, 0, SG_KMAP_ATOMIC); return r; } -- 2.1.4
[PATCH v2 02/21] libiscsi: Add an internal error code
This is a prep patch to add a new error code to libiscsi. We want to rework some kmap calls to be able to fail. When we do, we'd like to use this error code. This patch simply introduces ISCSI_TCP_INTERNAL_ERR and prints "Internal Error." when it gets hit. Signed-off-by: Logan Gunthorpe--- drivers/scsi/cxgbi/libcxgbi.c | 5 + include/scsi/libiscsi_tcp.h | 1 + 2 files changed, 6 insertions(+) diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c index bd7d39e..e38d0c1 100644 --- a/drivers/scsi/cxgbi/libcxgbi.c +++ b/drivers/scsi/cxgbi/libcxgbi.c @@ -1556,6 +1556,11 @@ static inline int read_pdu_skb(struct iscsi_conn *conn, */ iscsi_conn_printk(KERN_ERR, conn, "Invalid pdu or skb."); return -EFAULT; + case ISCSI_TCP_INTERNAL_ERR: + pr_info("skb 0x%p, off %u, %d, TCP_INTERNAL_ERR.\n", + skb, offset, offloaded); + iscsi_conn_printk(KERN_ERR, conn, "Internal error."); + return -EFAULT; case ISCSI_TCP_SEGMENT_DONE: log_debug(1 << CXGBI_DBG_PDU_RX, "skb 0x%p, off %u, %d, TCP_SEG_DONE, rc %d.\n", diff --git a/include/scsi/libiscsi_tcp.h b/include/scsi/libiscsi_tcp.h index 30520d5..90691ad 100644 --- a/include/scsi/libiscsi_tcp.h +++ b/include/scsi/libiscsi_tcp.h @@ -92,6 +92,7 @@ enum { ISCSI_TCP_SKB_DONE, /* skb is out of data */ ISCSI_TCP_CONN_ERR, /* iscsi layer has fired a conn err */ ISCSI_TCP_SUSPENDED,/* conn is suspended */ + ISCSI_TCP_INTERNAL_ERR, /* an internal error occurred */ }; extern void iscsi_tcp_hdr_recv_prep(struct iscsi_tcp_conn *tcp_conn); -- 2.1.4
Re: [PATCH v2] crypto: arm64/sha: Add constant operand modifier to ASM_EXPORT
On 25 April 2017 at 18:39, Matthias Kaehlckewrote: > Hi, > > El Tue, Apr 18, 2017 at 04:35:02PM +0100 Ard Biesheuvel ha dit: > >> On 18 April 2017 at 15:47, Paul Gortmaker >> wrote: >> > On Wed, Apr 5, 2017 at 2:34 PM, Matthias Kaehlcke >> > wrote: >> >> The operand is an integer constant, make the constness explicit by >> >> adding the modifier. This is needed for clang to generate valid code >> >> and also works with gcc. >> > >> > Actually it doesn't work with all gcc. I've got an older arm64 toolchain >> > that I >> > only use for syntax checking (and hence I don't care if it is the latest >> > and >> > greatest) and this commit breaks it: >> > >> > arch/arm64/crypto/sha1-ce-glue.c:21:2: error: invalid 'asm': invalid >> > operand prefix '%c' >> > asm(".globl " #sym "; .set " #sym ", %c0" :: "i"(val)); >> > >> > I'm currently reverting this change locally so I can continue to use the >> > old >> > toolchain: >> > >> > $ aarch64-linux-gnu-gcc --version >> > aarch64-linux-gnu-gcc (crosstool-NG linaro-1.13.1-4.8-2013.12 - Linaro >> > GCC 2013.11) 4.8.3 20131202 (prerelease) >> > Copyright (C) 2013 Free Software Foundation, Inc. >> > >> > $ aarch64-linux-gnu-as --version >> > GNU assembler (crosstool-NG linaro-1.13.1-4.8-2013.12 - Linaro GCC >> > 2013.11) 2.24.0.20131220 >> > Copyright 2013 Free Software Foundation, Inc. >> > >> > Maybe it is finally too old and nobody cares, but I thought it worth a >> > mention. >> > >> >> Thanks for the report. I think we care more about GCC 4.8 than about >> Clang, which argues for reverting this patch. >> >> I understand these issues must be frustrating if you are working on >> this stuff, but to me, it is not entirely obvious why we want to >> support Clang in the first place (i.e., what does it buy you if your >> distro/environment is not already using Clang for userland), and why >> the burden is on Linux to make modifications to support Clang, >> especially when it comes to GCC extensions such as inline assembly >> syntax. >> >> It is ultimately up to the maintainers to decide what to do with this >> patch, but my vote would be to revert it, especially given that the %c >> placeholder prefix is not documented anywhere, and appears to simply >> trigger some GCC internals that happen to do the right thing in this >> case. >> >> However, the I -> i change is arguably an improvement, and considering >> that the following >> >> asm("foo: .long %0" :: "i"(some value)) >> >> doesn't compile with clang either, I suggest you (Matthias) file a bug >> against Clang to get this fixed, and we can propose another patch just >> for the I->i change. > > I consulted with folks with more expertise in this area than myself. > This is their analysis of the situation: > > "The ARM ARM specifies that the correct AArch64 instruction assembly > syntax is to have a hash sign (#) before an immediate. > It does not specify that at all: """ The A64 assembly language does not require the # character to introduce constant immediate operands, but an assembler must allow immediate values introduced with or without the # character. ARM recommends that an A64 disassembler outputs a # before an immediate operand. """ (ARM DDI 0487A.g page C1-121) IOW, it only /recommends/ the # sign for *dis*assemblers. Big difference. > Therefore, every time an inline assembly constraint is used that > specifies to print an immediate (like 'i' or 'I'), the immediate > (e.g. 42) should be printed with the hash (e.g. #42). > > Therefore, if you're using an immediate constraint where the hash sign > must not be printed, you have to use the "c" operand modifier. The "c" > operand modifier apparently got introduced to gcc after the 4.8 > release. > My problem with the %c modifier is that it is completely undocumented, and appears in an internal GCC code generation code path. IOW, the GCC developers could also remove it at any time (although this is highly unlikely, of course) > The binutils assembler and the clang integrated assembler accept > immediates without the hash sign as a non-official extension. Nope. *That* is mandated by the ARM ARM, see above. > Some of > the immediate constraints on gcc seem to not print out the hash sign > either; which is why the variant in the linux kernel works with gcc. > Yes, and since it is perfectly legal for the "i" constraint not to have a #, I don't understand what the big deal is tbh. > In summary, it seems to me that the inline assembly with the %c0 > operand is the correct one and gcc 4.8 is simply too old to support > this." > OK, so we're back to having to choose between GCC 4.8 and Clang. > If the above is correct it seems that the solution is not to "fix" > clang, but to use different instructions for gcc<=4.8 and newer > compilers. I am aware that this is not a popular option. > > What do you think? > Perhaps I should just rework the code not to rely on inline asm at all. I
Re: [PATCH v2] crypto: arm64/sha: Add constant operand modifier to ASM_EXPORT
Hi, El Tue, Apr 18, 2017 at 04:35:02PM +0100 Ard Biesheuvel ha dit: > On 18 April 2017 at 15:47, Paul Gortmaker> wrote: > > On Wed, Apr 5, 2017 at 2:34 PM, Matthias Kaehlcke wrote: > >> The operand is an integer constant, make the constness explicit by > >> adding the modifier. This is needed for clang to generate valid code > >> and also works with gcc. > > > > Actually it doesn't work with all gcc. I've got an older arm64 toolchain > > that I > > only use for syntax checking (and hence I don't care if it is the latest and > > greatest) and this commit breaks it: > > > > arch/arm64/crypto/sha1-ce-glue.c:21:2: error: invalid 'asm': invalid > > operand prefix '%c' > > asm(".globl " #sym "; .set " #sym ", %c0" :: "i"(val)); > > > > I'm currently reverting this change locally so I can continue to use the old > > toolchain: > > > > $ aarch64-linux-gnu-gcc --version > > aarch64-linux-gnu-gcc (crosstool-NG linaro-1.13.1-4.8-2013.12 - Linaro > > GCC 2013.11) 4.8.3 20131202 (prerelease) > > Copyright (C) 2013 Free Software Foundation, Inc. > > > > $ aarch64-linux-gnu-as --version > > GNU assembler (crosstool-NG linaro-1.13.1-4.8-2013.12 - Linaro GCC > > 2013.11) 2.24.0.20131220 > > Copyright 2013 Free Software Foundation, Inc. > > > > Maybe it is finally too old and nobody cares, but I thought it worth a > > mention. > > > > Thanks for the report. I think we care more about GCC 4.8 than about > Clang, which argues for reverting this patch. > > I understand these issues must be frustrating if you are working on > this stuff, but to me, it is not entirely obvious why we want to > support Clang in the first place (i.e., what does it buy you if your > distro/environment is not already using Clang for userland), and why > the burden is on Linux to make modifications to support Clang, > especially when it comes to GCC extensions such as inline assembly > syntax. > > It is ultimately up to the maintainers to decide what to do with this > patch, but my vote would be to revert it, especially given that the %c > placeholder prefix is not documented anywhere, and appears to simply > trigger some GCC internals that happen to do the right thing in this > case. > > However, the I -> i change is arguably an improvement, and considering > that the following > > asm("foo: .long %0" :: "i"(some value)) > > doesn't compile with clang either, I suggest you (Matthias) file a bug > against Clang to get this fixed, and we can propose another patch just > for the I->i change. I consulted with folks with more expertise in this area than myself. This is their analysis of the situation: "The ARM ARM specifies that the correct AArch64 instruction assembly syntax is to have a hash sign (#) before an immediate. Therefore, every time an inline assembly constraint is used that specifies to print an immediate (like 'i' or 'I'), the immediate (e.g. 42) should be printed with the hash (e.g. #42). Therefore, if you're using an immediate constraint where the hash sign must not be printed, you have to use the "c" operand modifier. The "c" operand modifier apparently got introduced to gcc after the 4.8 release. The binutils assembler and the clang integrated assembler accept immediates without the hash sign as a non-official extension. Some of the immediate constraints on gcc seem to not print out the hash sign either; which is why the variant in the linux kernel works with gcc. In summary, it seems to me that the inline assembly with the %c0 operand is the correct one and gcc 4.8 is simply too old to support this." If the above is correct it seems that the solution is not to "fix" clang, but to use different instructions for gcc<=4.8 and newer compilers. I am aware that this is not a popular option. What do you think? Thanks Matthias
Re: [PATCH] crypto: sha512-mb - add some missing unlock on error
On Tue, 2017-04-25 at 12:18 +0300, Dan Carpenter wrote: > We recently added some new locking but missed the unlocks on these > error paths in sha512_ctx_mgr_submit(). Thanks for catching this issue. Acked-by: Tim Chen> > Fixes: c459bd7beda0 ("crypto: sha512-mb - Protect sha512 mb ctx mgr access") > Signed-off-by: Dan Carpenter > > diff --git a/arch/x86/crypto/sha512-mb/sha512_mb.c > b/arch/x86/crypto/sha512-mb/sha512_mb.c > index 2dd3674b5a1e..458409b7568d 100644 > --- a/arch/x86/crypto/sha512-mb/sha512_mb.c > +++ b/arch/x86/crypto/sha512-mb/sha512_mb.c > @@ -269,19 +269,19 @@ static struct sha512_hash_ctx > * LAST > */ > ctx->error = HASH_CTX_ERROR_INVALID_FLAGS; > - return ctx; > + goto unlock; > } > > if (ctx->status & HASH_CTX_STS_PROCESSING) { > /* Cannot submit to a currently processing job. */ > ctx->error = HASH_CTX_ERROR_ALREADY_PROCESSING; > - return ctx; > + goto unlock; > } > > if ((ctx->status & HASH_CTX_STS_COMPLETE) && !(flags & HASH_FIRST)) { > /* Cannot update a finished job. */ > ctx->error = HASH_CTX_ERROR_ALREADY_COMPLETED; > - return ctx; > + goto unlock; > } > > > @@ -363,6 +363,7 @@ static struct sha512_hash_ctx > } > > ctx = sha512_ctx_mgr_resubmit(mgr, ctx); > +unlock: > spin_unlock_irqrestore(>work_lock, irqflags); > return ctx; > }
Re: [PATCH 5/7] IB/hfi1: use pcie_flr instead of duplicating it
On Mon, 2017-04-24 at 16:35 +0200, Christoph Hellwig wrote: > On Mon, Apr 24, 2017 at 02:16:31PM +, Byczkowski, Jakub wrote: > > > > Tested-by: Jakub Byczkowski> > Are you (and Doug) ok with queueing this up in the PCI tree? I'm fine with that. Feel free to add my Acked-by to the hfi1 patch. -- Doug Ledford GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
[PATCH -next] crypto: stm32 - Fix OF module alias information
From: Wei YongjunThe module alias information passed to MODULE_DEVICE_TABLE() should use stm32_dt_ids instead of undefined sti_dt_ids. Fixes: b51dbe90912a ("crypto: stm32 - Support for STM32 CRC32 crypto module") Signed-off-by: Wei Yongjun --- drivers/crypto/stm32/stm32_crc32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/stm32/stm32_crc32.c b/drivers/crypto/stm32/stm32_crc32.c index 7652822..ec83b1e 100644 --- a/drivers/crypto/stm32/stm32_crc32.c +++ b/drivers/crypto/stm32/stm32_crc32.c @@ -306,7 +306,7 @@ static const struct of_device_id stm32_dt_ids[] = { { .compatible = "st,stm32f7-crc", }, {}, }; -MODULE_DEVICE_TABLE(of, sti_dt_ids); +MODULE_DEVICE_TABLE(of, stm32_dt_ids); static struct platform_driver stm32_crc_driver = { .probe = stm32_crc_probe,
[PATCH] crypto: ccp - Add a module author
CC:# 4.9.x+ Signed-off-by: Gary R Hook --- drivers/crypto/ccp/ccp-dev.c |1 + 1 file changed, 1 insertion(+) diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c index 92d1c6959f08..b7504562715c 100644 --- a/drivers/crypto/ccp/ccp-dev.c +++ b/drivers/crypto/ccp/ccp-dev.c @@ -31,6 +31,7 @@ #include "ccp-dev.h" MODULE_AUTHOR("Tom Lendacky "); +MODULE_AUTHOR("Gary R Hook "); MODULE_LICENSE("GPL"); MODULE_VERSION("1.0.0"); MODULE_DESCRIPTION("AMD Cryptographic Coprocessor driver");
[PATCH 3/5] crypto: caampkc - incapsulate dropping leading zeros into function
From: Radu AlexeThis function will be used into further patches. Signed-off-by: Radu Alexe Signed-off-by: Horia Geantă --- drivers/crypto/caam/caampkc.c | 13 + 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index 999ba18495b0..d2c6977ba82e 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -357,6 +357,14 @@ static void caam_rsa_free_key(struct caam_rsa_key *key) key->n_sz = 0; } +static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes) +{ + while (!**ptr && *nbytes) { + (*ptr)++; + (*nbytes)--; + } +} + /** * caam_read_raw_data - Read a raw byte stream as a positive integer. * The function skips buffer's leading zeros, copies the remained data @@ -370,10 +378,7 @@ static inline u8 *caam_read_raw_data(const u8 *buf, size_t *nbytes) { u8 *val; - while (!*buf && *nbytes) { - buf++; - (*nbytes)--; - } + caam_rsa_drop_leading_zeros(, nbytes); if (!*nbytes) return NULL; -- 2.12.0.264.gd6db3f216544
[PATCH 0/5] crypto: caampkc - extend RSA private key representation
This patch set adds support for the second and third RSA private key representations and extends caampkc to use the fastest key when all related components are present in the private key. Additionally a rsa tcrypt test has been added. Radu Alexe (4): crypto: tcrypt - include rsa test crypto: caampkc - incapsulate dropping leading zeros into function crypto: caampkc - add support for RSA key form 2 crypto: cammpkc - add support for RSA key form 3 Tudor Ambarus (1): crypto: caampkc - avoid kzalloc(0) in caam_read_raw_data crypto/tcrypt.c| 6 +- drivers/crypto/caam/caampkc.c | 463 +++-- drivers/crypto/caam/caampkc.h | 58 ++ drivers/crypto/caam/pdb.h | 62 ++ drivers/crypto/caam/pkc_desc.c | 36 5 files changed, 603 insertions(+), 22 deletions(-) -- 2.12.0.264.gd6db3f216544
[PATCH 2/5] crypto: caampkc - avoid kzalloc(0) in caam_read_raw_data
From: Tudor AmbarusThe function returns NULL if buf is composed only of zeros. Signed-off-by: Tudor Ambarus Signed-off-by: Horia Geantă --- drivers/crypto/caam/caampkc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index 49cbdcba7883..999ba18495b0 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -374,6 +374,8 @@ static inline u8 *caam_read_raw_data(const u8 *buf, size_t *nbytes) buf++; (*nbytes)--; } + if (!*nbytes) + return NULL; val = kzalloc(*nbytes, GFP_DMA | GFP_KERNEL); if (!val) -- 2.12.0.264.gd6db3f216544
[PATCH 5/5] crypto: cammpkc - add support for RSA key form 3
From: Radu AlexeCAAM RSA private key may have either of three representations. 1. The first representation consists of the pair (n, d), where the components have the following meanings: n the RSA modulus d the RSA private exponent 2. The second representation consists of the triplet (p, q, d), where the components have the following meanings: p the first prime factor of the RSA modulus n q the second prime factor of the RSA modulus n d the RSA private exponent 3. The third representation consists of the quintuple (p, q, dP, dQ, qInv), where the components have the following meanings: p the first prime factor of the RSA modulus n q the second prime factor of the RSA modulus n dP the first factors's CRT exponent dQ the second factors's CRT exponent qInv the (first) CRT coefficient The benefit of using the third or the second key form is lower computational cost for the decryption and signature operations. This patch adds support for the third RSA private key representations and extends caampkc to use the fastest key when all related components are present in the private key. Signed-off-by: Tudor Ambarus Signed-off-by: Radu Alexe Signed-off-by: Horia Geantă --- drivers/crypto/caam/caampkc.c | 219 - drivers/crypto/caam/caampkc.h | 22 - drivers/crypto/caam/pdb.h | 33 +++ drivers/crypto/caam/pkc_desc.c | 19 4 files changed, 291 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index 912e41700522..57f399caa977 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -20,6 +20,8 @@ sizeof(struct rsa_priv_f1_pdb)) #define DESC_RSA_PRIV_F2_LEN (2 * CAAM_CMD_SZ + \ sizeof(struct rsa_priv_f2_pdb)) +#define DESC_RSA_PRIV_F3_LEN (2 * CAAM_CMD_SZ + \ +sizeof(struct rsa_priv_f3_pdb)) static void rsa_io_unmap(struct device *dev, struct rsa_edesc *edesc, struct akcipher_request *req) @@ -73,6 +75,25 @@ static void rsa_priv_f2_unmap(struct device *dev, struct rsa_edesc *edesc, dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_TO_DEVICE); } +static void rsa_priv_f3_unmap(struct device *dev, struct rsa_edesc *edesc, + struct akcipher_request *req) +{ + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); + struct caam_rsa_key *key = >key; + struct rsa_priv_f3_pdb *pdb = >pdb.priv_f3; + size_t p_sz = key->p_sz; + size_t q_sz = key->p_sz; + + dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE); + dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE); + dma_unmap_single(dev, pdb->dp_dma, p_sz, DMA_TO_DEVICE); + dma_unmap_single(dev, pdb->dq_dma, q_sz, DMA_TO_DEVICE); + dma_unmap_single(dev, pdb->c_dma, p_sz, DMA_TO_DEVICE); + dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_TO_DEVICE); + dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_TO_DEVICE); +} + /* RSA Job Completion handler */ static void rsa_pub_done(struct device *dev, u32 *desc, u32 err, void *context) { @@ -127,6 +148,24 @@ static void rsa_priv_f2_done(struct device *dev, u32 *desc, u32 err, akcipher_request_complete(req, err); } +static void rsa_priv_f3_done(struct device *dev, u32 *desc, u32 err, +void *context) +{ + struct akcipher_request *req = context; + struct rsa_edesc *edesc; + + if (err) + caam_jr_strstatus(dev, err); + + edesc = container_of(desc, struct rsa_edesc, hw_desc[0]); + + rsa_priv_f3_unmap(dev, edesc, req); + rsa_io_unmap(dev, edesc, req); + kfree(edesc); + + akcipher_request_complete(req, err); +} + static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req, size_t desclen) { @@ -370,6 +409,97 @@ static int set_rsa_priv_f2_pdb(struct akcipher_request *req, return -ENOMEM; } +static int set_rsa_priv_f3_pdb(struct akcipher_request *req, + struct rsa_edesc *edesc) +{ + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); + struct caam_rsa_key *key = >key; + struct device *dev = ctx->dev; + struct rsa_priv_f3_pdb *pdb = >pdb.priv_f3; + int sec4_sg_index = 0; + size_t p_sz = key->p_sz; + size_t q_sz = key->p_sz; + + pdb->p_dma = dma_map_single(dev, key->p, p_sz, DMA_TO_DEVICE); + if (dma_mapping_error(dev, pdb->p_dma)) { + dev_err(dev, "Unable to map RSA prime factor p
[PATCH 4/5] crypto: caampkc - add support for RSA key form 2
From: Radu AlexeCAAM RSA private key may have either of three representations. 1. The first representation consists of the pair (n, d), where the components have the following meanings: n the RSA modulus d the RSA private exponent 2. The second representation consists of the triplet (p, q, d), where the components have the following meanings: p the first prime factor of the RSA modulus n q the second prime factor of the RSA modulus n d the RSA private exponent 3. The third representation consists of the quintuple (p, q, dP, dQ, qInv), where the components have the following meanings: p the first prime factor of the RSA modulus n q the second prime factor of the RSA modulus n dP the first factors's CRT exponent dQ the second factors's CRT exponent qInv the (first) CRT coefficient The benefit of using the third or the second key form is lower computational cost for the decryption and signature operations. This patch adds support for the second RSA private key representation. Signed-off-by: Tudor Ambarus Signed-off-by: Radu Alexe Signed-off-by: Horia Geantă --- drivers/crypto/caam/caampkc.c | 231 ++--- drivers/crypto/caam/caampkc.h | 38 +++ drivers/crypto/caam/pdb.h | 29 ++ drivers/crypto/caam/pkc_desc.c | 17 +++ 4 files changed, 298 insertions(+), 17 deletions(-) diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index d2c6977ba82e..912e41700522 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -18,6 +18,8 @@ #define DESC_RSA_PUB_LEN (2 * CAAM_CMD_SZ + sizeof(struct rsa_pub_pdb)) #define DESC_RSA_PRIV_F1_LEN (2 * CAAM_CMD_SZ + \ sizeof(struct rsa_priv_f1_pdb)) +#define DESC_RSA_PRIV_F2_LEN (2 * CAAM_CMD_SZ + \ +sizeof(struct rsa_priv_f2_pdb)) static void rsa_io_unmap(struct device *dev, struct rsa_edesc *edesc, struct akcipher_request *req) @@ -54,6 +56,23 @@ static void rsa_priv_f1_unmap(struct device *dev, struct rsa_edesc *edesc, dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE); } +static void rsa_priv_f2_unmap(struct device *dev, struct rsa_edesc *edesc, + struct akcipher_request *req) +{ + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); + struct caam_rsa_key *key = >key; + struct rsa_priv_f2_pdb *pdb = >pdb.priv_f2; + size_t p_sz = key->p_sz; + size_t q_sz = key->p_sz; + + dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE); + dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE); + dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE); + dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_TO_DEVICE); + dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_TO_DEVICE); +} + /* RSA Job Completion handler */ static void rsa_pub_done(struct device *dev, u32 *desc, u32 err, void *context) { @@ -90,6 +109,24 @@ static void rsa_priv_f1_done(struct device *dev, u32 *desc, u32 err, akcipher_request_complete(req, err); } +static void rsa_priv_f2_done(struct device *dev, u32 *desc, u32 err, +void *context) +{ + struct akcipher_request *req = context; + struct rsa_edesc *edesc; + + if (err) + caam_jr_strstatus(dev, err); + + edesc = container_of(desc, struct rsa_edesc, hw_desc[0]); + + rsa_priv_f2_unmap(dev, edesc, req); + rsa_io_unmap(dev, edesc, req); + kfree(edesc); + + akcipher_request_complete(req, err); +} + static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req, size_t desclen) { @@ -258,6 +295,81 @@ static int set_rsa_priv_f1_pdb(struct akcipher_request *req, return 0; } +static int set_rsa_priv_f2_pdb(struct akcipher_request *req, + struct rsa_edesc *edesc) +{ + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); + struct caam_rsa_key *key = >key; + struct device *dev = ctx->dev; + struct rsa_priv_f2_pdb *pdb = >pdb.priv_f2; + int sec4_sg_index = 0; + size_t p_sz = key->p_sz; + size_t q_sz = key->p_sz; + + pdb->d_dma = dma_map_single(dev, key->d, key->d_sz, DMA_TO_DEVICE); + if (dma_mapping_error(dev, pdb->d_dma)) { + dev_err(dev, "Unable to map RSA private exponent memory\n"); + return -ENOMEM; + } + + pdb->p_dma = dma_map_single(dev, key->p, p_sz, DMA_TO_DEVICE); + if (dma_mapping_error(dev, pdb->p_dma)) { + dev_err(dev,
[PATCH 1/5] crypto: tcrypt - include rsa test
From: Radu AlexeSigned-off-by: Radu Alexe Signed-off-by: Tudor Ambarus Signed-off-by: Horia Geantă --- crypto/tcrypt.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 9a11f3c2bf98..012fcd14c675 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c @@ -76,7 +76,7 @@ static char *check[] = { "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512", - NULL + "rsa", NULL }; struct tcrypt_result { @@ -1333,6 +1333,10 @@ static int do_test(const char *alg, u32 type, u32 mask, int m) ret += tcrypt_test("hmac(sha3-512)"); break; + case 115: + ret += tcrypt_test("rsa"); + break; + case 150: ret += tcrypt_test("ansi_cprng"); break; -- 2.12.0.264.gd6db3f216544
[PATCH] crypto: sha512-mb - add some missing unlock on error
We recently added some new locking but missed the unlocks on these error paths in sha512_ctx_mgr_submit(). Fixes: c459bd7beda0 ("crypto: sha512-mb - Protect sha512 mb ctx mgr access") Signed-off-by: Dan Carpenterdiff --git a/arch/x86/crypto/sha512-mb/sha512_mb.c b/arch/x86/crypto/sha512-mb/sha512_mb.c index 2dd3674b5a1e..458409b7568d 100644 --- a/arch/x86/crypto/sha512-mb/sha512_mb.c +++ b/arch/x86/crypto/sha512-mb/sha512_mb.c @@ -269,19 +269,19 @@ static struct sha512_hash_ctx * LAST */ ctx->error = HASH_CTX_ERROR_INVALID_FLAGS; - return ctx; + goto unlock; } if (ctx->status & HASH_CTX_STS_PROCESSING) { /* Cannot submit to a currently processing job. */ ctx->error = HASH_CTX_ERROR_ALREADY_PROCESSING; - return ctx; + goto unlock; } if ((ctx->status & HASH_CTX_STS_COMPLETE) && !(flags & HASH_FIRST)) { /* Cannot update a finished job. */ ctx->error = HASH_CTX_ERROR_ALREADY_COMPLETED; - return ctx; + goto unlock; } @@ -363,6 +363,7 @@ static struct sha512_hash_ctx } ctx = sha512_ctx_mgr_resubmit(mgr, ctx); +unlock: spin_unlock_irqrestore(>work_lock, irqflags); return ctx; }
Re: [PATCH v2] crypto: algif_aead - Require setkey before accept(2)
Am Dienstag, 25. April 2017, 10:47:48 CEST schrieb Herbert Xu: Hi Herbert, > Could you wait until the next merge window closes? Will do. Ciao Stephan
Re: [PATCH v2] crypto: algif_aead - Require setkey before accept(2)
On Mon, Apr 24, 2017 at 12:26:15PM +0200, Stephan Müller wrote: > Am Montag, 24. April 2017, 12:22:39 CEST schrieb Herbert Xu: > > Hi Herbert, > > > Patch applied. Thanks. > > Thank you. > > The patch regarding the memory management of algif_aead is affected by this > change as well. Shall I roll a new version of that patch for algif_aead or do > you want me to wait for another review round? Could you wait until the next merge window closes? Thanks, -- Email: Herbert XuHome Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
[PATCH] crypto: tcrypt: don't disable irqs and wait
The tcrypt AEAD cycles speed tests disables irqs during the test, which is broken at the very least since commit '1425d2d17f7309c6 ("crypto: tcrypt - Fix AEAD speed tests")' adds a wait for completion as part of the test and probably since switching to the new AEAD API. While the result of taking a cycle count diff may not mean much on SMP systems if the task migrates, it's good enough for tcrypt being the quick & dirty dev tool it is. It's also what all the other (i.e. hash) cycle speed tests do. Signed-off-by: Gilad Ben-YossefReported-by: Ofir Drang --- crypto/tcrypt.c | 4 1 file changed, 4 deletions(-) diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 9a11f3c..0dd6a43 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c @@ -138,8 +138,6 @@ static int test_aead_cycles(struct aead_request *req, int enc, int blen) int ret = 0; int i; - local_irq_disable(); - /* Warm-up run. */ for (i = 0; i < 4; i++) { if (enc) @@ -169,8 +167,6 @@ static int test_aead_cycles(struct aead_request *req, int enc, int blen) } out: - local_irq_enable(); - if (ret == 0) printk("1 operation in %lu cycles (%d bytes)\n", (cycles + 4) / 8, blen); -- 2.1.4
Re: [PATCH v3 2/3] crypto: inside-secure: add SafeXcel EIP197 crypto engine driver
Hi Stephan, On Mon, Apr 24, 2017 at 02:59:05PM +0200, Stephan Müller wrote: > Am Montag, 24. April 2017, 09:54:06 CEST schrieb Antoine Tenart: > > > +struct safexcel_cipher_ctx { > > + struct safexcel_context base; > > + struct safexcel_crypto_priv *priv; > > + > > + enum safexcel_cipher_direction direction; > > + u32 mode; > > + > > + __le32 key[8]; > > Can you please help me find the location where this memory is zeroized when > released? It's not, I'll fix this. > > +static void safexcel_cipher_token(struct safexcel_cipher_ctx *ctx, > > + struct crypto_async_request *async, > > + struct safexcel_command_desc *cdesc, > > + u32 length) > > +{ > > + struct ablkcipher_request *req = ablkcipher_request_cast(async); > > + struct safexcel_token *token; > > + unsigned offset = 0; > > + > > + if (ctx->mode == CONTEXT_CONTROL_CRYPTO_MODE_CBC) { > > + offset = AES_BLOCK_SIZE / sizeof(u32); > > + memcpy(cdesc->control_data.token, req->info, AES_BLOCK_SIZE); > > + > > + cdesc->control_data.options |= EIP197_OPTION_4_TOKEN_IV_CMD; > > + } > > + > > + token = (struct safexcel_token *)(cdesc->control_data.token + offset); > > + > > + token[0].opcode = EIP197_TOKEN_OPCODE_DIRECTION; > > + token[0].packet_length = length; > > + token[0].stat = EIP197_TOKEN_STAT_LAST_PACKET; > > + token[0].instructions = EIP197_TOKEN_INS_LAST | > > + EIP197_TOKEN_INS_TYPE_CRYTO | > > + EIP197_TOKEN_INS_TYPE_OUTPUT; > > +} > > + > > +static int safexcel_aes_setkey(struct crypto_ablkcipher *ctfm, const u8 > > *key, +unsigned int len) > > +{ > > You still use ablkcipher. I thought that it is on its way out in favor of the > skcipher API. Why do you stick to ablkcipher? > > Note, a change could be as simple as s/ablkcipher/skcipher/g Because I wasn't aware of this :) I'll update. > > + struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ctfm); > > + struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm); > > + struct crypto_aes_ctx aes; > > + int ret, i; > > + > > + ret = crypto_aes_expand_key(, key, len); > > + if (ret) { > > + crypto_ablkcipher_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN); > > + return ret; > > + } > > + > > + for (i = 0; i < len / sizeof(u32); i++) { > > + if (ctx->key[i] != cpu_to_le32(aes.key_enc[i])) { > > + ctx->base.needs_inv = true; > > + break; > > + } > > + } > > + > > + for (i = 0; i < len / sizeof(u32); i++) > > + ctx->key[i] = cpu_to_le32(aes.key_enc[i]); > > + > > + ctx->key_len = len; > > memzero_explicit(aes)? OK, I'll update. > > +static int safexcel_aes_send(struct crypto_async_request *async, > > +int ring, struct safexcel_request *request, > > +int *commands, int *results) > > +{ > > + struct ablkcipher_request *req = ablkcipher_request_cast(async); > > + struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(req->base.tfm); > > + struct safexcel_crypto_priv *priv = ctx->priv; > > + struct safexcel_command_desc *cdesc; > > + struct safexcel_result_desc *rdesc; > > + struct scatterlist *sg; > > + int nr_src, nr_dst, n_cdesc = 0, n_rdesc = 0, queued = req->nbytes; > > + int i, ret = 0; > > + > > + request->req = >base; > > + > > + if (req->src == req->dst) { > > + nr_src = dma_map_sg(priv->dev, req->src, > > + sg_nents_for_len(req->src, req->nbytes), > > + DMA_BIDIRECTIONAL); > > + nr_dst = nr_src; > > + if (!nr_src) > > + return -EINVAL; > > + } else { > > + nr_src = dma_map_sg(priv->dev, req->src, > > + sg_nents_for_len(req->src, req->nbytes), > > + DMA_TO_DEVICE); > > + if (!nr_src) > > + return -EINVAL; > > + > > + nr_dst = dma_map_sg(priv->dev, req->dst, > > + sg_nents_for_len(req->dst, req->nbytes), > > + DMA_FROM_DEVICE); > > + if (!nr_dst) { > > + dma_unmap_sg(priv->dev, req->src, > > +sg_nents_for_len(req->src, req->nbytes), > > +DMA_TO_DEVICE); > > + return -EINVAL; > > + } > > + } > > + > > + memcpy(ctx->base.ctxr->data, ctx->key, ctx->key_len); > > Is ctxr->data properly zeroized? No, I'll update. Thanks for the review! Antoine -- Antoine Ténart, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com signature.asc Description: PGP signature